1use crate::MultipartWrite;
6
7use futures::future::Future;
8use std::pin::Pin;
9use std::task::{Context, Poll};
10
11mod buffered;
12pub use buffered::Buffered;
13
14mod complete;
15pub use complete::Complete;
16
17mod fanout;
18pub use fanout::Fanout;
19
20mod feed;
21pub use feed::Feed;
22
23mod fold_ret;
24pub use fold_ret::FoldRet;
25
26mod flush;
27pub use flush::Flush;
28
29mod map;
30pub use map::Map;
31
32mod map_err;
33pub use map_err::MapErr;
34
35mod map_part;
36pub use map_part::MapPart;
37
38mod map_ret;
39pub use map_ret::MapRet;
40
41mod on_complete;
42pub use on_complete::OnComplete;
43
44mod send;
45pub use send::Send;
46
47mod then;
48pub use then::Then;
49
50mod with;
51pub use with::With;
52
53impl<Wr: MultipartWrite<Part>, Part> MultipartWriteExt<Part> for Wr {}
54
55pub trait MultipartWriteExt<Part>: MultipartWrite<Part> {
58 fn buffered(self, capacity: impl Into<Option<usize>>) -> Buffered<Self, Part>
63 where
64 Self: Sized,
65 {
66 Buffered::new(self, capacity.into().unwrap_or_default())
67 }
68
69 fn complete(&mut self) -> Complete<'_, Self, Part>
72 where
73 Self: Unpin,
74 {
75 Complete::new(self)
76 }
77
78 fn fanout<U>(self, other: U) -> Fanout<Self, U, Part>
82 where
83 Part: Clone,
84 U: MultipartWrite<Part, Error = Self::Error>,
85 Self: Sized,
86 {
87 Fanout::new(self, other)
88 }
89
90 fn feed(&mut self, part: Part) -> Feed<'_, Self, Part>
97 where
98 Self: Unpin,
99 {
100 Feed::new(self, part)
101 }
102
103 fn flush(&mut self) -> Flush<'_, Self, Part>
105 where
106 Self: Unpin,
107 {
108 Flush::new(self)
109 }
110
111 fn fold_ret<T, F>(self, id: T, f: F) -> FoldRet<Self, F, T>
115 where
116 F: FnMut(T, &Self::Ret) -> T,
117 Self: Sized,
118 {
119 FoldRet::new(self, id, f)
120 }
121
122 fn map<U, F>(self, f: F) -> Map<Self, F>
125 where
126 F: FnMut(Self::Output) -> U,
127 Self: Sized,
128 {
129 Map::new(self, f)
130 }
131
132 fn map_err<E, F>(self, f: F) -> MapErr<Self, F>
135 where
136 F: FnMut(Self::Error) -> E,
137 Self: Sized,
138 {
139 MapErr::new(self, f)
140 }
141
142 fn map_part<U, F>(self, f: F) -> MapPart<Self, F>
145 where
146 F: FnMut(U) -> Result<Part, Self::Error>,
147 Self: MultipartWrite<Part> + Sized,
148 {
149 MapPart::new(self, f)
150 }
151
152 fn map_ret<U, F>(self, f: F) -> MapRet<Self, F>
155 where
156 F: FnMut(Self::Ret) -> U,
157 Self: Sized,
158 {
159 MapRet::new(self, f)
160 }
161
162 fn on_complete<S, F, Fut>(self, s: S, f: F) -> OnComplete<Self, S, F, Fut>
167 where
168 F: FnMut(&mut S) -> Fut,
169 Fut: Future<Output = Result<Self, Self::Error>>,
170 Self: Sized,
171 {
172 OnComplete::new(self, s, f)
173 }
174
175 #[must_use = "futures do nothing unless polled"]
179 fn poll_ready_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
180 where
181 Self: Unpin,
182 {
183 Pin::new(self).poll_ready(cx)
184 }
185
186 #[must_use = "futures do nothing unless polled"]
190 fn poll_flush_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
191 where
192 Self: Unpin,
193 {
194 Pin::new(self).poll_flush(cx)
195 }
196
197 #[must_use = "futures do nothing unless polled"]
201 fn poll_complete_unpin(
202 &mut self,
203 cx: &mut Context<'_>,
204 ) -> Poll<Result<Self::Output, Self::Error>>
205 where
206 Self: Unpin,
207 {
208 Pin::new(self).poll_complete(cx)
209 }
210
211 fn send(&mut self, part: Part) -> Send<'_, Self, Part>
214 where
215 Self: Unpin,
216 {
217 Send::new(self, part)
218 }
219
220 fn then<U, F, Fut>(self, f: F) -> Then<Self, F, Fut>
222 where
223 F: FnMut(Self::Output) -> Fut,
224 Fut: Future<Output = U>,
225 Self: Sized,
226 {
227 Then::new(self, f)
228 }
229
230 fn with<U, Fut, F, E>(self, f: F) -> With<Self, Part, U, Fut, F>
235 where
236 F: FnMut(U) -> Fut,
237 Fut: Future<Output = Result<Part, E>>,
238 E: From<Self::Error>,
239 Self: Sized,
240 {
241 With::new(self, f)
242 }
243}