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
@@ -362,13 +360,13 @@ impl Body {
362
360
/// res.set_body(Body::from_file("/path/to/file").await?);
363
361
/// # Ok(()) }) }
364
362
/// ```
365
- #[ cfg( feature = "async_std" ) ]
363
+ #[ cfg( all ( feature = "async_std" , not ( target_os = "unknown" ) ) ) ]
366
364
pub async fn from_file < P > ( path : P ) -> io:: Result < Self >
367
365
where
368
- P : AsRef < Path > ,
366
+ P : AsRef < std :: path :: Path > ,
369
367
{
370
368
let path = path. as_ref ( ) ;
371
- let mut file = fs:: File :: open ( path) . await ?;
369
+ let mut file = async_std :: fs:: File :: open ( path) . await ?;
372
370
let len = file. metadata ( ) . await ?. len ( ) ;
373
371
374
372
// Look at magic bytes first, look at extension second, fall back to
@@ -476,7 +474,7 @@ impl BufRead for Body {
476
474
477
475
/// Look at first few bytes of a file to determine the mime type.
478
476
/// This is used for various binary formats such as images and videos.
479
- #[ cfg( feature = "async_std" ) ]
477
+ #[ cfg( all ( feature = "async_std" , not ( target_os = "unknown" ) ) ) ]
480
478
async fn peek_mime ( file : & mut async_std:: fs:: File ) -> io:: Result < Option < Mime > > {
481
479
// We need to read the first 300 bytes to correctly infer formats such as tar.
482
480
let mut buf = [ 0_u8 ; 300 ] ;
@@ -490,8 +488,8 @@ async fn peek_mime(file: &mut async_std::fs::File) -> io::Result<Option<Mime>> {
490
488
491
489
/// Look at the extension of a file to determine the mime type.
492
490
/// This is useful for plain-text formats such as HTML and CSS.
493
- #[ cfg( feature = "async_std" ) ]
494
- fn guess_ext ( path : & Path ) -> Option < Mime > {
491
+ #[ cfg( all ( feature = "async_std" , not ( target_os = "unknown" ) ) ) ]
492
+ fn guess_ext ( path : & std :: path :: Path ) -> Option < Mime > {
495
493
let ext = path. extension ( ) . map ( |p| p. to_str ( ) ) . flatten ( ) ;
496
494
match ext {
497
495
Some ( "html" ) => Some ( mime:: HTML ) ,
0 commit comments