1use futures_core::future::Future;
6use std::pin::Pin;
7use std::task::{Context, Poll};
8
9pub use crate::{BoxMultipartWrite, LocalBoxMultipartWrite, MultipartWrite};
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 map_err;
42pub use map_err::MapErr;
43
44mod map_ok;
45pub use map_ok::MapOk;
46
47mod returning;
48pub use returning::Returning;
49
50mod send_part;
51pub use send_part::SendPart;
52
53mod then;
54pub use then::Then;
55
56mod with;
57pub use with::With;
58
59impl<Wr: MultipartWrite<Part>, Part> MultipartWriteExt<Part> for Wr {}
60
61pub trait MultipartWriteExt<Part>: MultipartWrite<Part> {
64 fn and_then<T, E, Fut, F>(self, f: F) -> AndThen<Self, Fut, F>
71 where
72 F: FnMut(Self::Output) -> Fut,
73 Fut: Future<Output = Result<T, E>>,
74 E: From<Self::Error>,
75 Self: Sized,
76 {
77 AndThen::new(self, f)
78 }
79
80 fn boxed<'a>(self) -> BoxMultipartWrite<'a, Part, Self::Ret, Self::Output, Self::Error>
82 where
83 Self: Sized + Send + 'a,
84 {
85 Box::pin(self)
86 }
87
88 fn boxed_local<'a>(
92 self,
93 ) -> LocalBoxMultipartWrite<'a, Part, Self::Ret, Self::Output, Self::Error>
94 where
95 Self: Sized + 'a,
96 {
97 Box::pin(self)
98 }
99
100 fn buffered(self, capacity: impl Into<Option<usize>>) -> Buffered<Self, Part>
105 where
106 Self: Sized,
107 {
108 Buffered::new(self, capacity.into().unwrap_or_default())
109 }
110
111 fn complete(&mut self) -> Complete<'_, Self, Part>
114 where
115 Self: Unpin,
116 {
117 Complete::new(self)
118 }
119
120 fn fanout<U>(self, other: U) -> Fanout<Self, U, Part>
124 where
125 Part: Clone,
126 U: MultipartWrite<Part, Error = Self::Error>,
127 Self: Sized,
128 {
129 Fanout::new(self, other)
130 }
131
132 fn feed(&mut self, part: Part) -> Feed<'_, Self, Part>
139 where
140 Self: Unpin,
141 {
142 Feed::new(self, part)
143 }
144
145 fn filter<F>(self, f: F) -> Filter<Self, F>
151 where
152 F: FnMut(&Part) -> bool,
153 Self: Sized,
154 {
155 Filter::new(self, f)
156 }
157
158 fn filter_map<U, F>(self, f: F) -> FilterMap<Self, F>
164 where
165 F: FnMut(U) -> Option<Part>,
166 Self: Sized,
167 {
168 FilterMap::new(self, f)
169 }
170
171 fn flush(&mut self) -> Flush<'_, Self, Part>
173 where
174 Self: Unpin,
175 {
176 Flush::new(self)
177 }
178
179 fn fold_ret<T, F>(self, id: T, f: F) -> FoldRet<Self, T, F>
183 where
184 F: FnMut(T, &Self::Ret) -> T,
185 Self: Sized,
186 {
187 FoldRet::new(self, id, f)
188 }
189
190 fn map_ok<U, F>(self, f: F) -> MapOk<Self, F>
193 where
194 F: FnMut(Self::Output) -> U,
195 Self: Sized,
196 {
197 MapOk::new(self, f)
198 }
199
200 fn map_err<E, F>(self, f: F) -> MapErr<Self, F>
203 where
204 F: FnMut(Self::Error) -> E,
205 Self: Sized,
206 {
207 MapErr::new(self, f)
208 }
209
210 fn returning<U, F>(self, f: F) -> Returning<Self, F>
213 where
214 F: FnMut(Self::Ret) -> U,
215 Self: Sized,
216 {
217 Returning::new(self, f)
218 }
219
220 #[must_use = "futures do nothing unless polled"]
223 fn poll_ready_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
224 where
225 Self: Unpin,
226 {
227 Pin::new(self).poll_ready(cx)
228 }
229
230 #[must_use = "futures do nothing unless polled"]
233 fn poll_flush_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
234 where
235 Self: Unpin,
236 {
237 Pin::new(self).poll_flush(cx)
238 }
239
240 #[must_use = "futures do nothing unless polled"]
243 fn poll_complete_unpin(
244 &mut self,
245 cx: &mut Context<'_>,
246 ) -> Poll<Result<Self::Output, Self::Error>>
247 where
248 Self: Unpin,
249 {
250 Pin::new(self).poll_complete(cx)
251 }
252
253 fn send_part(&mut self, part: Part) -> SendPart<'_, Self, Part>
256 where
257 Self: Unpin,
258 {
259 SendPart::new(self, part)
260 }
261
262 fn then<T, E, Fut, F>(self, f: F) -> Then<Self, Fut, F>
265 where
266 F: FnMut(Result<Self::Output, Self::Error>) -> Fut,
267 Fut: Future<Output = Result<T, E>>,
268 E: From<Self::Error>,
269 Self: Sized,
270 {
271 Then::new(self, f)
272 }
273
274 fn with<U, E, Fut, F>(self, f: F) -> With<Self, Part, Fut, F>
280 where
281 F: FnMut(U) -> Fut,
282 Fut: Future<Output = Result<Part, E>>,
283 E: From<Self::Error>,
284 Self: Sized,
285 {
286 With::new(self, f)
287 }
288}