@@ -11,13 +11,12 @@ use futures_util::TryStreamExt;
11
11
use http:: HeaderMap ;
12
12
use http_body:: { Body as HttpBody , SizeHint } ;
13
13
14
- use super :: Chunk ;
15
14
use crate :: common:: { task, Future , Never , Pin , Poll } ;
16
15
use crate :: upgrade:: OnUpgrade ;
17
16
18
- type BodySender = mpsc:: Sender < Result < Chunk , crate :: Error > > ;
17
+ type BodySender = mpsc:: Sender < Result < Bytes , crate :: Error > > ;
19
18
20
- /// A stream of `Chunk `s, used when receiving bodies.
19
+ /// A stream of `Bytes `s, used when receiving bodies.
21
20
///
22
21
/// A good default `Payload` to use in many applications.
23
22
#[ must_use = "streams do nothing unless polled" ]
@@ -29,11 +28,11 @@ pub struct Body {
29
28
}
30
29
31
30
enum Kind {
32
- Once ( Option < Chunk > ) ,
31
+ Once ( Option < Bytes > ) ,
33
32
Chan {
34
33
content_length : Option < u64 > ,
35
34
abort_rx : oneshot:: Receiver < ( ) > ,
36
- rx : mpsc:: Receiver < Result < Chunk , crate :: Error > > ,
35
+ rx : mpsc:: Receiver < Result < Bytes , crate :: Error > > ,
37
36
} ,
38
37
H2 {
39
38
content_length : Option < u64 > ,
@@ -45,7 +44,7 @@ enum Kind {
45
44
// See https://github.com/rust-lang/rust/issues/57017
46
45
#[ cfg( feature = "stream" ) ]
47
46
Wrapped (
48
- Pin < Box < dyn Stream < Item = Result < Chunk , Box < dyn StdError + Send + Sync > > > + Send + Sync > > ,
47
+ Pin < Box < dyn Stream < Item = Result < Bytes , Box < dyn StdError + Send + Sync > > > + Send + Sync > > ,
49
48
) ,
50
49
}
51
50
@@ -152,7 +151,7 @@ impl Body {
152
151
pub fn wrap_stream < S , O , E > ( stream : S ) -> Body
153
152
where
154
153
S : Stream < Item = Result < O , E > > + Send + Sync + ' static ,
155
- O : Into < Chunk > + ' static ,
154
+ O : Into < Bytes > + ' static ,
156
155
E : Into < Box < dyn StdError + Send + Sync > > + ' static ,
157
156
{
158
157
let mapped = stream. map_ok ( Into :: into) . map_err ( Into :: into) ;
@@ -208,7 +207,7 @@ impl Body {
208
207
} )
209
208
}
210
209
211
- fn poll_eof ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < Option < crate :: Result < Chunk > > > {
210
+ fn poll_eof ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < Option < crate :: Result < Bytes > > > {
212
211
match self . take_delayed_eof ( ) {
213
212
Some ( DelayEof :: NotEof ( mut delay) ) => match self . poll_inner ( cx) {
214
213
ok @ Poll :: Ready ( Some ( Ok ( ..) ) ) | ok @ Poll :: Pending => {
@@ -237,7 +236,7 @@ impl Body {
237
236
}
238
237
}
239
238
240
- fn poll_inner ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < Option < crate :: Result < Chunk > > > {
239
+ fn poll_inner ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < Option < crate :: Result < Bytes > > > {
241
240
match self . kind {
242
241
Kind :: Once ( ref mut val) => Poll :: Ready ( val. take ( ) . map ( Ok ) ) ,
243
242
Kind :: Chan {
@@ -265,7 +264,7 @@ impl Body {
265
264
} => match ready ! ( h2. poll_data( cx) ) {
266
265
Some ( Ok ( bytes) ) => {
267
266
let _ = h2. flow_control ( ) . release_capacity ( bytes. len ( ) ) ;
268
- Poll :: Ready ( Some ( Ok ( Chunk :: from ( bytes) ) ) )
267
+ Poll :: Ready ( Some ( Ok ( bytes) ) )
269
268
}
270
269
Some ( Err ( e) ) => Poll :: Ready ( Some ( Err ( crate :: Error :: new_body ( e) ) ) ) ,
271
270
None => Poll :: Ready ( None ) ,
@@ -279,7 +278,7 @@ impl Body {
279
278
}
280
279
}
281
280
282
- pub ( super ) fn take_full_data ( & mut self ) -> Option < Chunk > {
281
+ pub ( super ) fn take_full_data ( & mut self ) -> Option < Bytes > {
283
282
if let Kind :: Once ( ref mut chunk) = self . kind {
284
283
chunk. take ( )
285
284
} else {
@@ -297,7 +296,7 @@ impl Default for Body {
297
296
}
298
297
299
298
impl HttpBody for Body {
300
- type Data = Chunk ;
299
+ type Data = Bytes ;
301
300
type Error = crate :: Error ;
302
301
303
302
fn poll_data (
@@ -362,7 +361,7 @@ impl fmt::Debug for Body {
362
361
#[ derive( Debug ) ]
363
362
struct Empty ;
364
363
#[ derive( Debug ) ]
365
- struct Full < ' a > ( & ' a Chunk ) ;
364
+ struct Full < ' a > ( & ' a Bytes ) ;
366
365
367
366
let mut builder = f. debug_tuple ( "Body" ) ;
368
367
match self . kind {
@@ -381,7 +380,7 @@ impl fmt::Debug for Body {
381
380
/// `Cargo.toml`.
382
381
#[ cfg( feature = "stream" ) ]
383
382
impl Stream for Body {
384
- type Item = crate :: Result < Chunk > ;
383
+ type Item = crate :: Result < Bytes > ;
385
384
386
385
fn poll_next ( self : Pin < & mut Self > , cx : & mut task:: Context < ' _ > ) -> Poll < Option < Self :: Item > > {
387
386
HttpBody :: poll_data ( self , cx)
@@ -393,22 +392,22 @@ impl Stream for Body {
393
392
/// This function requires enabling the `stream` feature in your
394
393
/// `Cargo.toml`.
395
394
#[ cfg( feature = "stream" ) ]
396
- impl From < Box < dyn Stream < Item = Result < Chunk , Box < dyn StdError + Send + Sync > > > + Send + Sync > >
395
+ impl From < Box < dyn Stream < Item = Result < Bytes , Box < dyn StdError + Send + Sync > > > + Send + Sync > >
397
396
for Body
398
397
{
399
398
#[ inline]
400
399
fn from (
401
400
stream : Box <
402
- dyn Stream < Item = Result < Chunk , Box < dyn StdError + Send + Sync > > > + Send + Sync ,
401
+ dyn Stream < Item = Result < Bytes , Box < dyn StdError + Send + Sync > > > + Send + Sync ,
403
402
> ,
404
403
) -> Body {
405
404
Body :: new ( Kind :: Wrapped ( stream. into ( ) ) )
406
405
}
407
406
}
408
407
409
- impl From < Chunk > for Body {
408
+ impl From < Bytes > for Body {
410
409
#[ inline]
411
- fn from ( chunk : Chunk ) -> Body {
410
+ fn from ( chunk : Bytes ) -> Body {
412
411
if chunk. is_empty ( ) {
413
412
Body :: empty ( )
414
413
} else {
@@ -417,24 +416,17 @@ impl From<Chunk> for Body {
417
416
}
418
417
}
419
418
420
- impl From < Bytes > for Body {
421
- #[ inline]
422
- fn from ( bytes : Bytes ) -> Body {
423
- Body :: from ( Chunk :: from ( bytes) )
424
- }
425
- }
426
-
427
419
impl From < Vec < u8 > > for Body {
428
420
#[ inline]
429
421
fn from ( vec : Vec < u8 > ) -> Body {
430
- Body :: from ( Chunk :: from ( vec) )
422
+ Body :: from ( Bytes :: from ( vec) )
431
423
}
432
424
}
433
425
434
426
impl From < & ' static [ u8 ] > for Body {
435
427
#[ inline]
436
428
fn from ( slice : & ' static [ u8 ] ) -> Body {
437
- Body :: from ( Chunk :: from ( slice) )
429
+ Body :: from ( Bytes :: from ( slice) )
438
430
}
439
431
}
440
432
@@ -451,14 +443,14 @@ impl From<Cow<'static, [u8]>> for Body {
451
443
impl From < String > for Body {
452
444
#[ inline]
453
445
fn from ( s : String ) -> Body {
454
- Body :: from ( Chunk :: from ( s. into_bytes ( ) ) )
446
+ Body :: from ( Bytes :: from ( s. into_bytes ( ) ) )
455
447
}
456
448
}
457
449
458
450
impl From < & ' static str > for Body {
459
451
#[ inline]
460
452
fn from ( slice : & ' static str ) -> Body {
461
- Body :: from ( Chunk :: from ( slice. as_bytes ( ) ) )
453
+ Body :: from ( Bytes :: from ( slice. as_bytes ( ) ) )
462
454
}
463
455
}
464
456
@@ -486,7 +478,7 @@ impl Sender {
486
478
}
487
479
488
480
/// Send data on this channel when it is ready.
489
- pub async fn send_data ( & mut self , chunk : Chunk ) -> crate :: Result < ( ) > {
481
+ pub async fn send_data ( & mut self , chunk : Bytes ) -> crate :: Result < ( ) > {
490
482
futures_util:: future:: poll_fn ( |cx| self . poll_ready ( cx) ) . await ?;
491
483
self . tx
492
484
. try_send ( Ok ( chunk) )
@@ -497,15 +489,15 @@ impl Sender {
497
489
///
498
490
/// # Errors
499
491
///
500
- /// Returns `Err(Chunk )` if the channel could not (currently) accept
501
- /// another `Chunk `.
492
+ /// Returns `Err(Bytes )` if the channel could not (currently) accept
493
+ /// another `Bytes `.
502
494
///
503
495
/// # Note
504
496
///
505
497
/// This is mostly useful for when trying to send from some other thread
506
498
/// that doesn't have an async context. If in an async context, prefer
507
499
/// [`send_data`][] instead.
508
- pub fn try_send_data ( & mut self , chunk : Chunk ) -> Result < ( ) , Chunk > {
500
+ pub fn try_send_data ( & mut self , chunk : Bytes ) -> Result < ( ) , Bytes > {
509
501
self . tx
510
502
. try_send ( Ok ( chunk) )
511
503
. map_err ( |err| err. into_inner ( ) . expect ( "just sent Ok" ) )
0 commit comments