6
6
//! This module is only available when the `sink` feature of this
7
7
//! library is activated, and it is activated by default.
8
8
9
+ use crate :: future:: Either ;
9
10
use core:: pin:: Pin ;
10
11
use futures_core:: future:: Future ;
11
12
use futures_core:: stream:: { Stream , TryStream } ;
12
13
use futures_core:: task:: { Context , Poll } ;
13
- use crate :: future:: Either ;
14
14
15
15
#[ cfg( feature = "compat" ) ]
16
16
use crate :: compat:: CompatSink ;
@@ -41,6 +41,9 @@ pub use self::send::Send;
41
41
mod send_all;
42
42
pub use self :: send_all:: SendAll ;
43
43
44
+ mod unfold;
45
+ pub use self :: unfold:: { unfold, Unfold } ;
46
+
44
47
mod with;
45
48
pub use self :: with:: With ;
46
49
@@ -69,10 +72,11 @@ pub trait SinkExt<Item>: Sink<Item> {
69
72
/// Note that this function consumes the given sink, returning a wrapped
70
73
/// version, much like `Iterator::map`.
71
74
fn with < U , Fut , F , E > ( self , f : F ) -> With < Self , Item , U , Fut , F >
72
- where F : FnMut ( U ) -> Fut ,
73
- Fut : Future < Output = Result < Item , E > > ,
74
- E : From < Self :: Error > ,
75
- Self : Sized
75
+ where
76
+ F : FnMut ( U ) -> Fut ,
77
+ Fut : Future < Output = Result < Item , E > > ,
78
+ E : From < Self :: Error > ,
79
+ Self : Sized ,
76
80
{
77
81
With :: new ( self , f)
78
82
}
@@ -110,9 +114,10 @@ pub trait SinkExt<Item>: Sink<Item> {
110
114
/// # });
111
115
/// ```
112
116
fn with_flat_map < U , St , F > ( self , f : F ) -> WithFlatMap < Self , Item , U , St , F >
113
- where F : FnMut ( U ) -> St ,
114
- St : Stream < Item = Result < Item , Self :: Error > > ,
115
- Self : Sized
117
+ where
118
+ F : FnMut ( U ) -> St ,
119
+ St : Stream < Item = Result < Item , Self :: Error > > ,
120
+ Self : Sized ,
116
121
{
117
122
WithFlatMap :: new ( self , f)
118
123
}
@@ -133,8 +138,9 @@ pub trait SinkExt<Item>: Sink<Item> {
133
138
134
139
/// Transforms the error returned by the sink.
135
140
fn sink_map_err < E , F > ( self , f : F ) -> SinkMapErr < Self , F >
136
- where F : FnOnce ( Self :: Error ) -> E ,
137
- Self : Sized ,
141
+ where
142
+ F : FnOnce ( Self :: Error ) -> E ,
143
+ Self : Sized ,
138
144
{
139
145
SinkMapErr :: new ( self , f)
140
146
}
@@ -143,13 +149,13 @@ pub trait SinkExt<Item>: Sink<Item> {
143
149
///
144
150
/// If wanting to map errors of a `Sink + Stream`, use `.sink_err_into().err_into()`.
145
151
fn sink_err_into < E > ( self ) -> err_into:: SinkErrInto < Self , Item , E >
146
- where Self : Sized ,
147
- Self :: Error : Into < E > ,
152
+ where
153
+ Self : Sized ,
154
+ Self :: Error : Into < E > ,
148
155
{
149
156
SinkErrInto :: new ( self )
150
157
}
151
158
152
-
153
159
/// Adds a fixed-size buffer to the current sink.
154
160
///
155
161
/// The resulting sink will buffer up to `capacity` items when the
@@ -164,14 +170,16 @@ pub trait SinkExt<Item>: Sink<Item> {
164
170
/// library is activated, and it is activated by default.
165
171
#[ cfg( feature = "alloc" ) ]
166
172
fn buffer ( self , capacity : usize ) -> Buffer < Self , Item >
167
- where Self : Sized ,
173
+ where
174
+ Self : Sized ,
168
175
{
169
176
Buffer :: new ( self , capacity)
170
177
}
171
178
172
179
/// Close the sink.
173
180
fn close ( & mut self ) -> Close < ' _ , Self , Item >
174
- where Self : Unpin ,
181
+ where
182
+ Self : Unpin ,
175
183
{
176
184
Close :: new ( self )
177
185
}
@@ -181,9 +189,10 @@ pub trait SinkExt<Item>: Sink<Item> {
181
189
/// This adapter clones each incoming item and forwards it to both this as well as
182
190
/// the other sink at the same time.
183
191
fn fanout < Si > ( self , other : Si ) -> Fanout < Self , Si >
184
- where Self : Sized ,
185
- Item : Clone ,
186
- Si : Sink < Item , Error =Self :: Error >
192
+ where
193
+ Self : Sized ,
194
+ Item : Clone ,
195
+ Si : Sink < Item , Error = Self :: Error > ,
187
196
{
188
197
Fanout :: new ( self , other)
189
198
}
@@ -193,7 +202,8 @@ pub trait SinkExt<Item>: Sink<Item> {
193
202
/// This adapter is intended to be used when you want to stop sending to the sink
194
203
/// until all current requests are processed.
195
204
fn flush ( & mut self ) -> Flush < ' _ , Self , Item >
196
- where Self : Unpin ,
205
+ where
206
+ Self : Unpin ,
197
207
{
198
208
Flush :: new ( self )
199
209
}
@@ -205,7 +215,8 @@ pub trait SinkExt<Item>: Sink<Item> {
205
215
/// to batch together items to send via `send_all`, rather than flushing
206
216
/// between each item.**
207
217
fn send ( & mut self , item : Item ) -> Send < ' _ , Self , Item >
208
- where Self : Unpin ,
218
+ where
219
+ Self : Unpin ,
209
220
{
210
221
Send :: new ( self , item)
211
222
}
@@ -221,12 +232,10 @@ pub trait SinkExt<Item>: Sink<Item> {
221
232
/// Doing `sink.send_all(stream)` is roughly equivalent to
222
233
/// `stream.forward(sink)`. The returned future will exhaust all items from
223
234
/// `stream` and send them to `self`.
224
- fn send_all < ' a , St > (
225
- & ' a mut self ,
226
- stream : & ' a mut St
227
- ) -> SendAll < ' a , Self , St >
228
- where St : TryStream < Ok = Item , Error = Self :: Error > + Stream + Unpin + ?Sized ,
229
- Self : Unpin ,
235
+ fn send_all < ' a , St > ( & ' a mut self , stream : & ' a mut St ) -> SendAll < ' a , Self , St >
236
+ where
237
+ St : TryStream < Ok = Item , Error = Self :: Error > + Stream + Unpin + ?Sized ,
238
+ Self : Unpin ,
230
239
{
231
240
SendAll :: new ( self , stream)
232
241
}
@@ -237,8 +246,9 @@ pub trait SinkExt<Item>: Sink<Item> {
237
246
/// This can be used in combination with the `right_sink` method to write `if`
238
247
/// statements that evaluate to different streams in different branches.
239
248
fn left_sink < Si2 > ( self ) -> Either < Self , Si2 >
240
- where Si2 : Sink < Item , Error = Self :: Error > ,
241
- Self : Sized
249
+ where
250
+ Si2 : Sink < Item , Error = Self :: Error > ,
251
+ Self : Sized ,
242
252
{
243
253
Either :: Left ( self )
244
254
}
@@ -249,8 +259,9 @@ pub trait SinkExt<Item>: Sink<Item> {
249
259
/// This can be used in combination with the `left_sink` method to write `if`
250
260
/// statements that evaluate to different streams in different branches.
251
261
fn right_sink < Si1 > ( self ) -> Either < Si1 , Self >
252
- where Si1 : Sink < Item , Error = Self :: Error > ,
253
- Self : Sized
262
+ where
263
+ Si1 : Sink < Item , Error = Self :: Error > ,
264
+ Self : Sized ,
254
265
{
255
266
Either :: Right ( self )
256
267
}
@@ -260,39 +271,44 @@ pub trait SinkExt<Item>: Sink<Item> {
260
271
#[ cfg( feature = "compat" ) ]
261
272
#[ cfg_attr( docsrs, doc( cfg( feature = "compat" ) ) ) ]
262
273
fn compat ( self ) -> CompatSink < Self , Item >
263
- where Self : Sized + Unpin ,
274
+ where
275
+ Self : Sized + Unpin ,
264
276
{
265
277
CompatSink :: new ( self )
266
278
}
267
-
279
+
268
280
/// A convenience method for calling [`Sink::poll_ready`] on [`Unpin`]
269
281
/// sink types.
270
282
fn poll_ready_unpin ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > >
271
- where Self : Unpin
283
+ where
284
+ Self : Unpin ,
272
285
{
273
286
Pin :: new ( self ) . poll_ready ( cx)
274
287
}
275
288
276
289
/// A convenience method for calling [`Sink::start_send`] on [`Unpin`]
277
290
/// sink types.
278
291
fn start_send_unpin ( & mut self , item : Item ) -> Result < ( ) , Self :: Error >
279
- where Self : Unpin
292
+ where
293
+ Self : Unpin ,
280
294
{
281
295
Pin :: new ( self ) . start_send ( item)
282
296
}
283
297
284
298
/// A convenience method for calling [`Sink::poll_flush`] on [`Unpin`]
285
299
/// sink types.
286
300
fn poll_flush_unpin ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > >
287
- where Self : Unpin
301
+ where
302
+ Self : Unpin ,
288
303
{
289
304
Pin :: new ( self ) . poll_flush ( cx)
290
305
}
291
306
292
307
/// A convenience method for calling [`Sink::poll_close`] on [`Unpin`]
293
308
/// sink types.
294
309
fn poll_close_unpin ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > >
295
- where Self : Unpin
310
+ where
311
+ Self : Unpin ,
296
312
{
297
313
Pin :: new ( self ) . poll_close ( cx)
298
314
}
0 commit comments