File tree Expand file tree Collapse file tree 3 files changed +25
-20
lines changed Expand file tree Collapse file tree 3 files changed +25
-20
lines changed Original file line number Diff line number Diff line change @@ -215,6 +215,16 @@ impl From<Vec<u8>> for Body {
215
215
}
216
216
}
217
217
218
+ impl < ' a > From < & ' a [ u8 ] > for Body {
219
+ fn from ( b : & ' a [ u8 ] ) -> Self {
220
+ Self {
221
+ length : Some ( b. len ( ) ) ,
222
+ reader : Box :: new ( io:: Cursor :: new ( b. to_owned ( ) ) ) ,
223
+ mime : mime:: BYTE_STREAM ,
224
+ }
225
+ }
226
+ }
227
+
218
228
impl Read for Body {
219
229
#[ allow( missing_doc_code_examples) ]
220
230
fn poll_read (
Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ impl From<Response> for http::Response<Body> {
137
137
. status ( status)
138
138
. version ( version) ;
139
139
headers_to_hyperium_headers ( res. as_mut ( ) , builder. headers_mut ( ) . unwrap ( ) ) ;
140
- builder. body ( res. into ( ) ) . unwrap ( )
140
+ let body = res. take_body ( ) ;
141
+ builder. body ( body) . unwrap ( )
141
142
}
142
143
}
Original file line number Diff line number Diff line change @@ -511,32 +511,26 @@ impl AsMut<Headers> for Response {
511
511
}
512
512
}
513
513
514
- impl From < Response > for Body {
515
- fn from ( res : Response ) -> Body {
516
- res . body
514
+ impl From < ( ) > for Response {
515
+ fn from ( _ : ( ) ) -> Self {
516
+ Response :: new ( StatusCode :: NoContent )
517
517
}
518
518
}
519
519
520
- impl From < String > for Response {
521
- fn from ( s : String ) -> Self {
522
- let mut res = Response :: new ( StatusCode :: Ok ) ;
523
- res. set_body ( s) ;
524
- res
525
- }
526
- }
527
-
528
- impl < ' a > From < & ' a str > for Response {
529
- fn from ( s : & ' a str ) -> Self {
530
- let mut res = Response :: new ( StatusCode :: Ok ) ;
531
- res. set_body ( s) ;
532
- res
520
+ impl From < StatusCode > for Response {
521
+ fn from ( s : StatusCode ) -> Self {
522
+ Response :: new ( s)
533
523
}
534
524
}
535
525
536
- impl From < Vec < u8 > > for Response {
537
- fn from ( b : Vec < u8 > ) -> Self {
526
+ impl < T > From < T > for Response
527
+ where
528
+ T : Into < Body > ,
529
+ {
530
+ fn from ( value : T ) -> Self {
531
+ let body: Body = value. into ( ) ;
538
532
let mut res = Response :: new ( StatusCode :: Ok ) ;
539
- res. set_body ( b ) ;
533
+ res. set_body ( body ) ;
540
534
res
541
535
}
542
536
}
You can’t perform that action at this time.
0 commit comments