1
1
use std:: borrow:: Cow ;
2
- #[ cfg( feature = "stream" ) ]
3
- use std:: error:: Error as StdError ;
4
2
use std:: fmt;
5
3
6
4
use bytes:: Bytes ;
7
5
use futures_channel:: mpsc;
8
6
use futures_channel:: oneshot;
9
7
use futures_core:: Stream ; // for mpsc::Receiver
10
- #[ cfg( feature = "stream" ) ]
11
- use futures_util:: TryStreamExt ;
12
8
use http:: HeaderMap ;
13
9
use http_body:: { Body as HttpBody , SizeHint } ;
14
10
15
11
use super :: DecodedLength ;
16
- #[ cfg( feature = "stream" ) ]
17
- use crate :: common:: sync_wrapper:: SyncWrapper ;
18
12
use crate :: common:: Future ;
19
13
#[ cfg( all( feature = "client" , any( feature = "http1" , feature = "http2" ) ) ) ]
20
14
use crate :: common:: Never ;
@@ -56,12 +50,6 @@ enum Kind {
56
50
} ,
57
51
#[ cfg( feature = "ffi" ) ]
58
52
Ffi ( crate :: ffi:: UserBody ) ,
59
- #[ cfg( feature = "stream" ) ]
60
- Wrapped (
61
- SyncWrapper <
62
- Pin < Box < dyn Stream < Item = Result < Bytes , Box < dyn StdError + Send + Sync > > > + Send > > ,
63
- > ,
64
- ) ,
65
53
}
66
54
67
55
struct Extra {
@@ -164,39 +152,6 @@ impl Body {
164
152
( tx, rx)
165
153
}
166
154
167
- /// Wrap a futures `Stream` in a box inside `Body`.
168
- ///
169
- /// # Example
170
- ///
171
- /// ```
172
- /// # use hyper::Body;
173
- /// let chunks: Vec<Result<_, std::io::Error>> = vec![
174
- /// Ok("hello"),
175
- /// Ok(" "),
176
- /// Ok("world"),
177
- /// ];
178
- ///
179
- /// let stream = futures_util::stream::iter(chunks);
180
- ///
181
- /// let body = Body::wrap_stream(stream);
182
- /// ```
183
- ///
184
- /// # Optional
185
- ///
186
- /// This function requires enabling the `stream` feature in your
187
- /// `Cargo.toml`.
188
- #[ cfg( feature = "stream" ) ]
189
- #[ cfg_attr( docsrs, doc( cfg( feature = "stream" ) ) ) ]
190
- pub fn wrap_stream < S , O , E > ( stream : S ) -> Body
191
- where
192
- S : Stream < Item = Result < O , E > > + Send + ' static ,
193
- O : Into < Bytes > + ' static ,
194
- E : Into < Box < dyn StdError + Send + Sync > > + ' static ,
195
- {
196
- let mapped = stream. map_ok ( Into :: into) . map_err ( Into :: into) ;
197
- Body :: new ( Kind :: Wrapped ( SyncWrapper :: new ( Box :: pin ( mapped) ) ) )
198
- }
199
-
200
155
fn new ( kind : Kind ) -> Body {
201
156
Body { kind, extra : None }
202
157
}
@@ -329,12 +284,6 @@ impl Body {
329
284
330
285
#[ cfg( feature = "ffi" ) ]
331
286
Kind :: Ffi ( ref mut body) => body. poll_data ( cx) ,
332
-
333
- #[ cfg( feature = "stream" ) ]
334
- Kind :: Wrapped ( ref mut s) => match ready ! ( s. get_mut( ) . as_mut( ) . poll_next( cx) ) {
335
- Some ( res) => Poll :: Ready ( Some ( res. map_err ( crate :: Error :: new_body) ) ) ,
336
- None => Poll :: Ready ( None ) ,
337
- } ,
338
287
}
339
288
}
340
289
@@ -405,8 +354,6 @@ impl HttpBody for Body {
405
354
Kind :: H2 { recv : ref h2, .. } => h2. is_end_stream ( ) ,
406
355
#[ cfg( feature = "ffi" ) ]
407
356
Kind :: Ffi ( ..) => false ,
408
- #[ cfg( feature = "stream" ) ]
409
- Kind :: Wrapped ( ..) => false ,
410
357
}
411
358
}
412
359
@@ -426,8 +373,6 @@ impl HttpBody for Body {
426
373
match self . kind {
427
374
Kind :: Once ( Some ( ref val) ) => SizeHint :: with_exact ( val. len ( ) as u64 ) ,
428
375
Kind :: Once ( None ) => SizeHint :: with_exact ( 0 ) ,
429
- #[ cfg( feature = "stream" ) ]
430
- Kind :: Wrapped ( ..) => SizeHint :: default ( ) ,
431
376
Kind :: Chan { content_length, .. } => opt_len ! ( content_length) ,
432
377
#[ cfg( all( feature = "http2" , any( feature = "client" , feature = "server" ) ) ) ]
433
378
Kind :: H2 { content_length, .. } => opt_len ! ( content_length) ,
@@ -457,33 +402,6 @@ impl fmt::Debug for Body {
457
402
}
458
403
}
459
404
460
- /// # Optional
461
- ///
462
- /// This function requires enabling the `stream` feature in your
463
- /// `Cargo.toml`.
464
- #[ cfg( feature = "stream" ) ]
465
- impl Stream for Body {
466
- type Item = crate :: Result < Bytes > ;
467
-
468
- fn poll_next ( self : Pin < & mut Self > , cx : & mut task:: Context < ' _ > ) -> Poll < Option < Self :: Item > > {
469
- HttpBody :: poll_data ( self , cx)
470
- }
471
- }
472
-
473
- /// # Optional
474
- ///
475
- /// This function requires enabling the `stream` feature in your
476
- /// `Cargo.toml`.
477
- #[ cfg( feature = "stream" ) ]
478
- impl From < Box < dyn Stream < Item = Result < Bytes , Box < dyn StdError + Send + Sync > > > + Send > > for Body {
479
- #[ inline]
480
- fn from (
481
- stream : Box < dyn Stream < Item = Result < Bytes , Box < dyn StdError + Send + Sync > > > + Send > ,
482
- ) -> Body {
483
- Body :: new ( Kind :: Wrapped ( SyncWrapper :: new ( stream. into ( ) ) ) )
484
- }
485
- }
486
-
487
405
impl From < Bytes > for Body {
488
406
#[ inline]
489
407
fn from ( chunk : Bytes ) -> Body {
0 commit comments