Skip to content

Commit 10c599c

Browse files
committed
cargo fmt
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent f7beeff commit 10c599c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/method.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::convert::TryFrom;
12
use std::error::Error;
23
use std::fmt::{self, Display};
34
use std::str::FromStr;
@@ -86,3 +87,10 @@ impl FromStr for Method {
8687
}
8788
}
8889
}
90+
91+
impl<'a> TryFrom<&'a str> for Method {
92+
type Error = ParseError;
93+
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
94+
s.parse()
95+
}
96+
}

src/request.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use async_std::io::{self, BufRead, Read};
22

33
use std::borrow::Borrow;
4+
use std::convert::TryInto;
45
use std::fmt::{self, Debug};
56
use std::pin::Pin;
67
use std::task::{Context, Poll};
@@ -35,12 +36,16 @@ pin_project_lite::pin_project! {
3536

3637
impl Request {
3738
/// Create a new request.
38-
pub fn new(
39-
method: impl Into<Method>,
39+
pub fn new<M>(
40+
method: M,
4041
url: Url,
41-
) -> Result<Self, Box<dyn std::error::Error + Send + Sync + 'static>> {
42+
) -> Result<Self, Box<dyn std::error::Error + Send + Sync + 'static>>
43+
where
44+
M: TryInto<Method>,
45+
<M as TryInto<Method>>::Error: Sync + Send + std::error::Error + 'static,
46+
{
4247
Ok(Self {
43-
method: method.into(),
48+
method: method.try_into()?,
4449
url,
4550
headers: Headers::new(),
4651
body_reader: Box::new(io::empty()),

0 commit comments

Comments
 (0)