Commit 10c599c 1 parent f7beeff commit 10c599c Copy full SHA for 10c599c
File tree 2 files changed +17
-4
lines changed
2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change
1
+ use std:: convert:: TryFrom ;
1
2
use std:: error:: Error ;
2
3
use std:: fmt:: { self , Display } ;
3
4
use std:: str:: FromStr ;
@@ -86,3 +87,10 @@ impl FromStr for Method {
86
87
}
87
88
}
88
89
}
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
+ }
Original file line number Diff line number Diff line change 1
1
use async_std:: io:: { self , BufRead , Read } ;
2
2
3
3
use std:: borrow:: Borrow ;
4
+ use std:: convert:: TryInto ;
4
5
use std:: fmt:: { self , Debug } ;
5
6
use std:: pin:: Pin ;
6
7
use std:: task:: { Context , Poll } ;
@@ -35,12 +36,16 @@ pin_project_lite::pin_project! {
35
36
36
37
impl Request {
37
38
/// Create a new request.
38
- pub fn new (
39
- method : impl Into < Method > ,
39
+ pub fn new < M > (
40
+ method : M ,
40
41
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
+ {
42
47
Ok ( Self {
43
- method : method. into ( ) ,
48
+ method : method. try_into ( ) ? ,
44
49
url,
45
50
headers : Headers :: new ( ) ,
46
51
body_reader : Box :: new ( io:: empty ( ) ) ,
You can’t perform that action at this time.
0 commit comments