1
- use crate :: stream:: { StreamExt , Fuse } ;
1
+ use crate :: stream:: { StreamExt , TryStreamExt , Fuse , IntoStream } ;
2
+ use core:: fmt;
2
3
use core:: pin:: Pin ;
3
4
use futures_core:: future:: Future ;
4
- use futures_core:: stream:: Stream ;
5
+ use futures_core:: stream:: TryStream ;
5
6
use futures_core:: task:: { Context , Poll } ;
6
7
use futures_sink:: Sink ;
7
8
8
9
/// Future for the [`send_all`](super::SinkExt::send_all) method.
9
10
#[ allow( explicit_outlives_requirements) ] // https://github.com/rust-lang/rust/issues/60993
10
- #[ derive( Debug ) ]
11
11
#[ must_use = "futures do nothing unless you `.await` or poll them" ]
12
12
pub struct SendAll < ' a , Si , St >
13
13
where
14
14
Si : ?Sized ,
15
- St : Stream + ?Sized ,
15
+ St : ?Sized ,
16
+ & ' a mut St : TryStream ,
16
17
{
17
18
sink : & ' a mut Si ,
18
- stream : Fuse < & ' a mut St > ,
19
- buffered : Option < St :: Item > ,
19
+ stream : Fuse < IntoStream < & ' a mut St > > ,
20
+ buffered : Option < <& ' a mut St as TryStream >:: Ok > ,
21
+ }
22
+
23
+ impl < ' a , Si , St > fmt:: Debug for SendAll < ' a , Si , St >
24
+ where
25
+ Si : fmt:: Debug + ?Sized ,
26
+ St : fmt:: Debug + ?Sized ,
27
+ & ' a mut St : TryStream ,
28
+ <& ' a mut St as TryStream >:: Ok : fmt:: Debug ,
29
+ {
30
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
31
+ f. debug_struct ( "SendAll" )
32
+ . field ( "sink" , & self . sink )
33
+ . field ( "stream" , & self . stream )
34
+ . field ( "buffered" , & self . buffered )
35
+ . finish ( )
36
+ }
20
37
}
21
38
22
39
// Pinning is never projected to any fields
23
- impl < Si , St > Unpin for SendAll < ' _ , Si , St >
40
+ impl < ' a , Si , St > Unpin for SendAll < ' a , Si , St >
24
41
where
25
42
Si : Unpin + ?Sized ,
26
- St : Stream + Unpin + ?Sized ,
43
+ St : ?Sized ,
44
+ & ' a mut St : TryStream + Unpin ,
27
45
{ }
28
46
29
- impl < ' a , Si , St > SendAll < ' a , Si , St >
47
+ impl < ' a , Si , St , Ok , Error > SendAll < ' a , Si , St >
30
48
where
31
- Si : Sink < St :: Item > + Unpin + ?Sized ,
32
- St : Stream + Unpin + ?Sized ,
49
+ Si : Sink < Ok , Error = Error > + Unpin + ?Sized ,
50
+ St : ?Sized ,
51
+ & ' a mut St : TryStream < Ok = Ok , Error = Error > + Unpin ,
33
52
{
34
53
pub ( super ) fn new (
35
54
sink : & ' a mut Si ,
36
55
stream : & ' a mut St ,
37
56
) -> SendAll < ' a , Si , St > {
38
57
SendAll {
39
58
sink,
40
- stream : stream. fuse ( ) ,
59
+ stream : stream. into_stream ( ) . fuse ( ) ,
41
60
buffered : None ,
42
61
}
43
62
}
44
63
45
64
fn try_start_send (
46
65
& mut self ,
47
66
cx : & mut Context < ' _ > ,
48
- item : St :: Item ,
67
+ item : < & ' a mut St as TryStream > :: Ok ,
49
68
) -> Poll < Result < ( ) , Si :: Error > > {
50
69
debug_assert ! ( self . buffered. is_none( ) ) ;
51
70
match Pin :: new ( & mut self . sink ) . poll_ready ( cx) ? {
@@ -60,12 +79,13 @@ where
60
79
}
61
80
}
62
81
63
- impl < Si , St > Future for SendAll < ' _ , Si , St >
82
+ impl < ' a , Si , St , Ok , Error > Future for SendAll < ' a , Si , St >
64
83
where
65
- Si : Sink < St :: Item > + Unpin + ?Sized ,
66
- St : Stream + Unpin + ?Sized ,
84
+ Si : Sink < Ok , Error = Error > + Unpin + ?Sized ,
85
+ St : ?Sized ,
86
+ & ' a mut St : TryStream < Ok = Ok , Error = Error > + Unpin ,
67
87
{
68
- type Output = Result < ( ) , Si :: Error > ;
88
+ type Output = Result < ( ) , Error > ;
69
89
70
90
fn poll (
71
91
mut self : Pin < & mut Self > ,
79
99
}
80
100
81
101
loop {
82
- match this. stream . poll_next_unpin ( cx) {
102
+ match this. stream . try_poll_next_unpin ( cx) ? {
83
103
Poll :: Ready ( Some ( item) ) => {
84
104
ready ! ( this. try_start_send( cx, item) ) ?
85
105
}
0 commit comments