Skip to content

Commit 2d795d0

Browse files
committed
Fix compilation on wasm32-unknown-unknown
1 parent 7e06db5 commit 2d795d0

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/body.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use async_std::fs;
21
use async_std::io::prelude::*;
32
use async_std::io::{self, Cursor};
43
use serde::{de::DeserializeOwned, Serialize};
54

65
use std::fmt::{self, Debug};
7-
use std::path::Path;
86
use std::pin::Pin;
97
use std::task::{Context, Poll};
108

@@ -357,13 +355,13 @@ impl Body {
357355
/// res.set_body(Body::from_file("/path/to/file").await?);
358356
/// # Ok(()) }) }
359357
/// ```
360-
#[cfg(feature = "async_std")]
358+
#[cfg(all(feature = "async_std", not(target_os = "unknown")))]
361359
pub async fn from_file<P>(path: P) -> io::Result<Self>
362360
where
363-
P: AsRef<Path>,
361+
P: AsRef<std::path::Path>,
364362
{
365363
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?;
367365
let len = file.metadata().await?.len();
368366

369367
// Look at magic bytes first, look at extension second, fall back to
@@ -471,7 +469,7 @@ impl BufRead for Body {
471469

472470
/// Look at first few bytes of a file to determine the mime type.
473471
/// 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")))]
475473
async fn peek_mime(file: &mut async_std::fs::File) -> io::Result<Option<Mime>> {
476474
// We need to read the first 300 bytes to correctly infer formats such as tar.
477475
let mut buf = [0_u8; 300];
@@ -485,8 +483,8 @@ async fn peek_mime(file: &mut async_std::fs::File) -> io::Result<Option<Mime>> {
485483

486484
/// Look at the extension of a file to determine the mime type.
487485
/// 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> {
490488
let ext = path.extension().map(|p| p.to_str()).flatten();
491489
match ext {
492490
Some("html") => Some(mime::HTML),

src/method.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,19 @@ impl<'a> std::convert::TryFrom<&'a str> for Method {
9292
Self::from_str(value)
9393
}
9494
}
95+
96+
impl AsRef<str> for Method {
97+
fn as_ref(&self) -> &str {
98+
match self {
99+
Self::Get => "GET",
100+
Self::Head => "HEAD",
101+
Self::Post => "POST",
102+
Self::Put => "PUT",
103+
Self::Delete => "DELETE",
104+
Self::Connect => "CONNECT",
105+
Self::Options => "OPTIONS",
106+
Self::Trace => "TRACE",
107+
Self::Patch => "PATCH",
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)