Skip to content

Commit 7d92267

Browse files
authored
Merge pull request #153 from Perseus101/fix-wasm-compilation
Fix compilation on wasm32-unknown-unknown
2 parents 08ee3d2 + 2d795d0 commit 7d92267

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

@@ -362,13 +360,13 @@ impl Body {
362360
/// res.set_body(Body::from_file("/path/to/file").await?);
363361
/// # Ok(()) }) }
364362
/// ```
365-
#[cfg(feature = "async_std")]
363+
#[cfg(all(feature = "async_std", not(target_os = "unknown")))]
366364
pub async fn from_file<P>(path: P) -> io::Result<Self>
367365
where
368-
P: AsRef<Path>,
366+
P: AsRef<std::path::Path>,
369367
{
370368
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?;
372370
let len = file.metadata().await?.len();
373371

374372
// Look at magic bytes first, look at extension second, fall back to
@@ -476,7 +474,7 @@ impl BufRead for Body {
476474

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

491489
/// Look at the extension of a file to determine the mime type.
492490
/// 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> {
495493
let ext = path.extension().map(|p| p.to_str()).flatten();
496494
match ext {
497495
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)