1use crate::{BoxMultipartWrite, LocalBoxMultipartWrite, MultipartWrite};
6
7use futures_core::future::Future;
8use std::pin::Pin;
9use std::task::{Context, Poll};
10
11mod and_then;
12pub use and_then::AndThen;
13
14mod buffered;
15pub use buffered::Buffered;
16
17mod complete;
18pub use complete::Complete;
19
20mod extend;
21pub use extend::{Extend, extend};
22
23mod fanout;
24pub use fanout::Fanout;
25
26mod feed;
27pub use feed::Feed;
28
29mod filter;
30pub use filter::Filter;
31
32mod filter_map;
33pub use filter_map::FilterMap;
34
35mod fold_ret;
36pub use fold_ret::FoldRet;
37
38mod flush;
39pub use flush::Flush;
40
41mod fuse;
42pub use fuse::Fuse;
43
44mod lift;
45pub use lift::Lift;
46
47mod map_err;
48pub use map_err::MapErr;
49
50mod map_ret;
51pub use map_ret::MapRet;
52
53mod map_ok;
54pub use map_ok::MapOk;
55
56mod resolve;
57pub use resolve::{Resolve, resolve};
58
59mod send_part;
60pub use send_part::SendPart;
61
62mod then;
63pub use then::Then;
64
65mod with;
66pub use with::With;
67
68impl<Wr: MultipartWrite<Part>, Part> MultipartWriteExt<Part> for Wr {}
69
70pub trait MultipartWriteExt<Part>: MultipartWrite<Part> {
73 fn and_then<T, E, Fut, F>(self, f: F) -> AndThen<Self, Fut, F>
80 where
81 F: FnMut(Self::Output) -> Fut,
82 Fut: Future<Output = Result<T, E>>,
83 E: From<Self::Error>,
84 Self: Sized,
85 {
86 assert_writer::<Part, Self::Ret, E, T, _>(AndThen::new(self, f))
87 }
88
89 fn boxed<'a>(self) -> BoxMultipartWrite<'a, Part, Self::Ret, Self::Output, Self::Error>
91 where
92 Self: Sized + Send + 'a,
93 {
94 Box::pin(self)
95 }
96
97 fn boxed_local<'a>(
101 self,
102 ) -> LocalBoxMultipartWrite<'a, Part, Self::Ret, Self::Output, Self::Error>
103 where
104 Self: Sized + 'a,
105 {
106 Box::pin(self)
107 }
108
109 fn buffered(self, capacity: impl Into<Option<usize>>) -> Buffered<Self, Part>
114 where
115 Self: Sized,
116 {
117 assert_writer::<Part, (), Self::Error, Self::Output, _>(Buffered::new(
118 self,
119 capacity.into().unwrap_or_default(),
120 ))
121 }
122
123 fn complete(&mut self) -> Complete<'_, Self, Part>
126 where
127 Self: Unpin,
128 {
129 Complete::new(self)
130 }
131
132 fn fanout<U>(self, other: U) -> Fanout<Self, U, Part>
136 where
137 Part: Clone,
138 U: MultipartWrite<Part, Error = Self::Error>,
139 Self: Sized,
140 {
141 assert_writer::<Part, (Self::Ret, U::Ret), Self::Error, (Self::Output, U::Output), _>(
142 Fanout::new(self, other),
143 )
144 }
145
146 fn feed(&mut self, part: Part) -> Feed<'_, Self, Part>
153 where
154 Self: Unpin,
155 {
156 Feed::new(self, part)
157 }
158
159 fn filter<F>(self, f: F) -> Filter<Self, F>
165 where
166 F: FnMut(&Part) -> bool,
167 Self: Sized,
168 {
169 assert_writer::<Part, Option<Self::Ret>, Self::Error, Self::Output, _>(Filter::new(self, f))
170 }
171
172 fn filter_map<U, F>(self, f: F) -> FilterMap<Self, F>
178 where
179 F: FnMut(U) -> Option<Part>,
180 Self: Sized,
181 {
182 assert_writer::<U, Option<Self::Ret>, Self::Error, Self::Output, _>(FilterMap::new(self, f))
183 }
184
185 fn flush(&mut self) -> Flush<'_, Self, Part>
187 where
188 Self: Unpin,
189 {
190 Flush::new(self)
191 }
192
193 fn fold_ret<T, F>(self, id: T, f: F) -> FoldRet<Self, T, F>
197 where
198 F: FnMut(T, &Self::Ret) -> T,
199 Self: Sized,
200 {
201 assert_writer::<Part, Self::Ret, Self::Error, (T, Self::Output), _>(FoldRet::new(
202 self, id, f,
203 ))
204 }
205
206 fn fuse<F>(self, f: F) -> Fuse<Self, F>
212 where
213 F: FnMut(&Self::Output) -> bool,
214 Self: Sized,
215 {
216 assert_writer::<Part, Option<Self::Ret>, Self::Error, Option<Self::Output>, _>(Fuse::new(
217 self, f,
218 ))
219 }
220
221 fn lift<U, T>(self, other: U) -> Lift<Self, U, Part>
230 where
231 Self: Sized,
232 Self::Error: From<U::Error>,
233 U: MultipartWrite<T, Output = Part>,
234 {
235 assert_writer::<T, U::Ret, Self::Error, Self::Output, _>(Lift::new(self, other))
236 }
237
238 fn map_err<E, F>(self, f: F) -> MapErr<Self, F>
241 where
242 F: FnMut(Self::Error) -> E,
243 Self: Sized,
244 {
245 assert_writer::<Part, Self::Ret, E, Self::Output, _>(MapErr::new(self, f))
246 }
247
248 fn map_ok<U, F>(self, f: F) -> MapOk<Self, F>
251 where
252 F: FnMut(Self::Output) -> U,
253 Self: Sized,
254 {
255 assert_writer::<Part, Self::Ret, Self::Error, U, _>(MapOk::new(self, f))
256 }
257
258 fn map_ret<U, F>(self, f: F) -> MapRet<Self, F>
261 where
262 F: FnMut(Self::Ret) -> U,
263 Self: Sized,
264 {
265 assert_writer::<Part, U, Self::Error, Self::Output, _>(MapRet::new(self, f))
266 }
267
268 #[must_use = "futures do nothing unless polled"]
271 fn poll_ready_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
272 where
273 Self: Unpin,
274 {
275 Pin::new(self).poll_ready(cx)
276 }
277
278 #[must_use = "futures do nothing unless polled"]
281 fn poll_flush_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
282 where
283 Self: Unpin,
284 {
285 Pin::new(self).poll_flush(cx)
286 }
287
288 #[must_use = "futures do nothing unless polled"]
291 fn poll_complete_unpin(
292 &mut self,
293 cx: &mut Context<'_>,
294 ) -> Poll<Result<Self::Output, Self::Error>>
295 where
296 Self: Unpin,
297 {
298 Pin::new(self).poll_complete(cx)
299 }
300
301 fn send_part(&mut self, part: Part) -> SendPart<'_, Self, Part>
304 where
305 Self: Unpin,
306 {
307 SendPart::new(self, part)
308 }
309
310 fn then<T, E, Fut, F>(self, f: F) -> Then<Self, Fut, F>
313 where
314 F: FnMut(Result<Self::Output, Self::Error>) -> Fut,
315 Fut: Future<Output = Result<T, E>>,
316 E: From<Self::Error>,
317 Self: Sized,
318 {
319 assert_writer::<Part, Self::Ret, E, T, _>(Then::new(self, f))
320 }
321
322 fn with<U, E, Fut, F>(self, f: F) -> With<Self, Part, Fut, F>
328 where
329 F: FnMut(U) -> Fut,
330 Fut: Future<Output = Result<Part, E>>,
331 E: From<Self::Error>,
332 Self: Sized,
333 {
334 assert_writer::<U, (), E, Self::Output, _>(With::new(self, f))
335 }
336}
337
338fn assert_writer<Part, R, E, T, Wr>(wr: Wr) -> Wr
339where
340 Wr: MultipartWrite<Part, Ret = R, Error = E, Output = T>,
341{
342 wr
343}