File tree Expand file tree Collapse file tree 4 files changed +51
-0
lines changed Expand file tree Collapse file tree 4 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ use std:: pin:: Pin ;
2+ use std:: collections:: LinkedList ;
3+
4+ use crate :: prelude:: * ;
5+ use crate :: stream:: { Extend , IntoStream } ;
6+
7+ impl < T > Extend < T > for LinkedList < T > {
8+ fn stream_extend < ' a , S : IntoStream < Item = T > + ' a > (
9+ & ' a mut self ,
10+ stream : S ,
11+ ) -> Pin < Box < dyn Future < Output = ( ) > + ' a > > {
12+ let stream = stream. into_stream ( ) ;
13+ //TODO: Add this back in when size_hint is added to Stream/StreamExt
14+ //let (lower_bound, _) = stream.size_hint();
15+ //self.reserve(lower_bound);
16+ Box :: pin ( stream. for_each ( move |item| self . push_back ( item) ) )
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ use std:: pin:: Pin ;
2+ use std:: collections:: LinkedList ;
3+
4+ use crate :: stream:: { Extend , FromStream , IntoStream } ;
5+
6+ impl < T > FromStream < T > for LinkedList < T > {
7+ #[ inline]
8+ fn from_stream < ' a , S : IntoStream < Item = T > > (
9+ stream : S ,
10+ ) -> Pin < Box < dyn core:: future:: Future < Output = Self > + ' a > >
11+ where
12+ <S as IntoStream >:: IntoStream : ' a ,
13+ {
14+ let stream = stream. into_stream ( ) ;
15+
16+ Box :: pin ( async move {
17+ pin_utils:: pin_mut!( stream) ;
18+
19+ let mut out = LinkedList :: new ( ) ;
20+ out. stream_extend ( stream) . await ;
21+ out
22+ } )
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ //! The Rust doubly-linked list with owned nodes
2+
3+ mod extend;
4+ mod from_stream;
5+
6+ #[ doc( inline) ]
7+ pub use std:: collections:: LinkedList ;
Original file line number Diff line number Diff line change @@ -9,10 +9,12 @@ pub mod hash_set;
99pub mod btree_map;
1010pub mod btree_set;
1111pub mod binary_heap;
12+ pub mod linked_list;
1213
1314pub use vec_deque:: VecDeque ;
1415pub use hash_map:: HashMap ;
1516pub use hash_set:: HashSet ;
1617pub use btree_map:: BTreeMap ;
1718pub use btree_set:: BTreeSet ;
1819pub use binary_heap:: BinaryHeap ;
20+ pub use linked_list:: LinkedList ;
You can’t perform that action at this time.
0 commit comments