File tree 1 file changed +18
-4
lines changed
1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,17 @@ type BodyReader = dyn BufRead + Unpin + Send + 'static;
12
12
13
13
pin_project_lite:: pin_project! {
14
14
/// An HTTP request.
15
+ ///
16
+ /// ```
17
+ /// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
18
+ /// #
19
+ /// use http_types::{Url, Method, Request};
20
+ ///
21
+ /// let url = Url::parse("https://example.com")?;
22
+ /// let mut req = Request::new(Method::Get, url)?;
23
+ /// #
24
+ /// # Ok(()) }
25
+ /// ```
15
26
pub struct Request {
16
27
method: Method ,
17
28
url: Url ,
@@ -24,14 +35,17 @@ pin_project_lite::pin_project! {
24
35
25
36
impl Request {
26
37
/// Create a new request.
27
- pub fn new ( method : Method , url : Url ) -> Self {
28
- Self {
29
- method,
38
+ pub fn new (
39
+ method : impl Into < Method > ,
40
+ url : Url ,
41
+ ) -> Result < Self , Box < dyn std:: error:: Error + Send + Sync + ' static > > {
42
+ Ok ( Self {
43
+ method : method. into ( ) ,
30
44
url,
31
45
headers : Headers :: new ( ) ,
32
46
body_reader : Box :: new ( io:: empty ( ) ) ,
33
47
length : Some ( 0 ) ,
34
- }
48
+ } )
35
49
}
36
50
37
51
/// Get the HTTP method
You can’t perform that action at this time.
0 commit comments