@@ -151,8 +151,8 @@ pub struct RequestBuilder<'a, U: IntoUrl> {
151
151
impl < ' a , U : IntoUrl > RequestBuilder < ' a , U > {
152
152
153
153
/// Set a request body to be sent.
154
- pub fn body < B : IntoBody < ' a > > ( mut self , body : B ) -> RequestBuilder < ' a , U > {
155
- self . body = Some ( body. into_body ( ) ) ;
154
+ pub fn body < B : Into < Body < ' a > > > ( mut self , body : B ) -> RequestBuilder < ' a , U > {
155
+ self . body = Some ( body. into ( ) ) ;
156
156
self
157
157
}
158
158
@@ -190,17 +190,17 @@ impl<'a, U: IntoUrl> RequestBuilder<'a, U> {
190
190
} ;
191
191
192
192
let mut body = if can_have_body {
193
- body. map ( |b| b . into_body ( ) )
193
+ body
194
194
} else {
195
- None
195
+ None
196
196
} ;
197
197
198
198
loop {
199
199
let mut req = try!( Request :: with_connector ( method. clone ( ) , url. clone ( ) , & mut client. connector ) ) ;
200
200
headers. as_ref ( ) . map ( |headers| req. headers_mut ( ) . extend ( headers. iter ( ) ) ) ;
201
201
202
202
match ( can_have_body, body. as_ref ( ) ) {
203
- ( true , Some ( ref body) ) => match body. size ( ) {
203
+ ( true , Some ( body) ) => match body. size ( ) {
204
204
Some ( size) => req. headers_mut ( ) . set ( ContentLength ( size) ) ,
205
205
None => ( ) , // chunked, Request will add it automatically
206
206
} ,
@@ -251,13 +251,7 @@ impl<'a, U: IntoUrl> RequestBuilder<'a, U> {
251
251
}
252
252
}
253
253
254
- /// A helper trait to allow overloading of the body parameter.
255
- pub trait IntoBody < ' a > {
256
- /// Consumes self into an instance of `Body`.
257
- fn into_body ( self ) -> Body < ' a > ;
258
- }
259
-
260
- /// The target enum for the IntoBody trait.
254
+ /// An enum of possible body types for a Request.
261
255
pub enum Body < ' a > {
262
256
/// A Reader does not necessarily know it's size, so it is chunked.
263
257
ChunkedBody ( & ' a mut ( Read + ' a ) ) ,
@@ -288,32 +282,31 @@ impl<'a> Read for Body<'a> {
288
282
}
289
283
}
290
284
291
- // To allow someone to pass a `Body::SizedBody()` themselves.
292
- impl < ' a > IntoBody < ' a > for Body < ' a > {
285
+ impl < ' a > Into < Body < ' a > > for & ' a [ u8 ] {
293
286
#[ inline]
294
- fn into_body ( self ) -> Body < ' a > {
295
- self
287
+ fn into ( self ) -> Body < ' a > {
288
+ Body :: BufBody ( self , self . len ( ) )
296
289
}
297
290
}
298
291
299
- impl < ' a > IntoBody < ' a > for & ' a [ u8 ] {
292
+ impl < ' a > Into < Body < ' a > > for & ' a str {
300
293
#[ inline]
301
- fn into_body ( self ) -> Body < ' a > {
302
- Body :: BufBody ( self , self . len ( ) )
294
+ fn into ( self ) -> Body < ' a > {
295
+ self . as_bytes ( ) . into ( )
303
296
}
304
297
}
305
298
306
- impl < ' a > IntoBody < ' a > for & ' a str {
299
+ impl < ' a > Into < Body < ' a > > for & ' a String {
307
300
#[ inline]
308
- fn into_body ( self ) -> Body < ' a > {
309
- self . as_bytes ( ) . into_body ( )
301
+ fn into ( self ) -> Body < ' a > {
302
+ self . as_bytes ( ) . into ( )
310
303
}
311
304
}
312
305
313
- impl < ' a , R : Read > IntoBody < ' a > for & ' a mut R {
306
+ impl < ' a , R : Read > From < & ' a mut R > for Body < ' a > {
314
307
#[ inline]
315
- fn into_body ( self ) -> Body < ' a > {
316
- Body :: ChunkedBody ( self )
308
+ fn from ( r : & ' a mut R ) -> Body < ' a > {
309
+ Body :: ChunkedBody ( r )
317
310
}
318
311
}
319
312
0 commit comments