3
3
//! This module contains a number of functions for working with `Stream`s,
4
4
//! including the `StreamExt` trait which adds methods to `Stream` types.
5
5
6
+ use crate :: future:: Either ;
6
7
use core:: pin:: Pin ;
7
8
use futures_core:: future:: Future ;
8
9
use futures_core:: stream:: { FusedStream , Stream } ;
@@ -13,7 +14,8 @@ use futures_core::task::{Context, Poll};
13
14
use futures_sink:: Sink ;
14
15
#[ cfg( feature = "alloc" ) ]
15
16
use alloc:: boxed:: Box ;
16
- use crate :: future:: Either ;
17
+ #[ cfg( feature = "alloc" ) ]
18
+ use futures_core:: stream:: { BoxStream , LocalBoxStream } ;
17
19
18
20
mod iter;
19
21
pub use self :: iter:: { iter, Iter } ;
@@ -894,8 +896,21 @@ pub trait StreamExt: Stream {
894
896
/// This method is only available when the `std` or `alloc` feature of this
895
897
/// library is activated, and it is activated by default.
896
898
#[ cfg( feature = "alloc" ) ]
897
- fn boxed ( self ) -> Pin < Box < Self > >
898
- where Self : Sized
899
+ fn boxed < ' a > ( self ) -> BoxStream < ' a , Self :: Item >
900
+ where Self : Sized + Send + ' a
901
+ {
902
+ Box :: pin ( self )
903
+ }
904
+
905
+ /// Wrap the stream in a Box, pinning it.
906
+ ///
907
+ /// Similar to `boxed`, but without the `Send` requirement.
908
+ ///
909
+ /// This method is only available when the `std` or `alloc` feature of this
910
+ /// library is activated, and it is activated by default.
911
+ #[ cfg( feature = "alloc" ) ]
912
+ fn boxed_local < ' a > ( self ) -> LocalBoxStream < ' a , Self :: Item >
913
+ where Self : Sized + ' a
899
914
{
900
915
Box :: pin ( self )
901
916
}
0 commit comments