1
- use async_std:: fs;
2
1
use async_std:: io:: prelude:: * ;
3
2
use async_std:: io:: { self , Cursor } ;
4
3
use serde:: { de:: DeserializeOwned , Serialize } ;
5
4
6
5
use std:: fmt:: { self , Debug } ;
7
- use std:: path:: Path ;
8
6
use std:: pin:: Pin ;
9
7
use std:: task:: { Context , Poll } ;
10
8
@@ -357,13 +355,13 @@ impl Body {
357
355
/// res.set_body(Body::from_file("/path/to/file").await?);
358
356
/// # Ok(()) }) }
359
357
/// ```
360
- #[ cfg( feature = "async_std" ) ]
358
+ #[ cfg( all ( feature = "async_std" , not ( target_os = "unknown" ) ) ) ]
361
359
pub async fn from_file < P > ( path : P ) -> io:: Result < Self >
362
360
where
363
- P : AsRef < Path > ,
361
+ P : AsRef < std :: path :: Path > ,
364
362
{
365
363
let path = path. as_ref ( ) ;
366
- let mut file = fs:: File :: open ( path) . await ?;
364
+ let mut file = async_std :: fs:: File :: open ( path) . await ?;
367
365
let len = file. metadata ( ) . await ?. len ( ) ;
368
366
369
367
// Look at magic bytes first, look at extension second, fall back to
@@ -471,7 +469,7 @@ impl BufRead for Body {
471
469
472
470
/// Look at first few bytes of a file to determine the mime type.
473
471
/// This is used for various binary formats such as images and videos.
474
- #[ cfg( feature = "async_std" ) ]
472
+ #[ cfg( all ( feature = "async_std" , not ( target_os = "unknown" ) ) ) ]
475
473
async fn peek_mime ( file : & mut async_std:: fs:: File ) -> io:: Result < Option < Mime > > {
476
474
// We need to read the first 300 bytes to correctly infer formats such as tar.
477
475
let mut buf = [ 0_u8 ; 300 ] ;
@@ -485,8 +483,8 @@ async fn peek_mime(file: &mut async_std::fs::File) -> io::Result<Option<Mime>> {
485
483
486
484
/// Look at the extension of a file to determine the mime type.
487
485
/// This is useful for plain-text formats such as HTML and CSS.
488
- #[ cfg( feature = "async_std" ) ]
489
- fn guess_ext ( path : & Path ) -> Option < Mime > {
486
+ #[ cfg( all ( feature = "async_std" , not ( target_os = "unknown" ) ) ) ]
487
+ fn guess_ext ( path : & std :: path :: Path ) -> Option < Mime > {
490
488
let ext = path. extension ( ) . map ( |p| p. to_str ( ) ) . flatten ( ) ;
491
489
match ext {
492
490
Some ( "html" ) => Some ( mime:: HTML ) ,
0 commit comments