1#![cfg_attr(docsrs, feature(doc_cfg))]
11use std::ops::DerefMut;
12use std::pin::Pin;
13use std::task::{Context, Poll};
14
15pub mod io;
16pub mod stream;
17pub mod write;
18
19pub mod prelude {
21 pub use super::MultipartWrite;
22 pub use super::stream::{self, MultipartStreamExt as _};
23 pub use super::write::{self, MultipartWriteExt as _};
24}
25
26pub trait MultipartWrite<Part> {
29 type Ret;
31
32 type Output;
34
35 type Error;
37
38 fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
47
48 fn start_send(self: Pin<&mut Self>, part: Part) -> Result<Self::Ret, Self::Error>;
61
62 fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
67
68 fn poll_complete(
73 self: Pin<&mut Self>,
74 cx: &mut Context<'_>,
75 ) -> Poll<Result<Self::Output, Self::Error>>;
76}
77
78pub type BoxMultipartWrite<'a, Part, R, T, E> =
81 Pin<Box<dyn MultipartWrite<Part, Ret = R, Output = T, Error = E> + Send + 'a>>;
82
83pub type LocalBoxMultipartWrite<'a, Part, R, T, E> =
85 Pin<Box<dyn MultipartWrite<Part, Ret = R, Output = T, Error = E> + 'a>>;
86
87pub trait FusedMultipartWrite<Part>: MultipartWrite<Part> {
90 fn is_terminated(&self) -> bool;
92}
93
94impl<W: ?Sized + MultipartWrite<Part> + Unpin, Part> MultipartWrite<Part> for &mut W {
95 type Ret = W::Ret;
96 type Output = W::Output;
97 type Error = W::Error;
98
99 fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
100 Pin::new(&mut **self).poll_ready(cx)
101 }
102
103 fn start_send(mut self: Pin<&mut Self>, part: Part) -> Result<Self::Ret, Self::Error> {
104 Pin::new(&mut **self).start_send(part)
105 }
106
107 fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
108 Pin::new(&mut **self).poll_flush(cx)
109 }
110
111 fn poll_complete(
112 mut self: Pin<&mut Self>,
113 cx: &mut Context<'_>,
114 ) -> Poll<Result<Self::Output, Self::Error>> {
115 Pin::new(&mut **self).poll_complete(cx)
116 }
117}
118
119impl<W: ?Sized + FusedMultipartWrite<Part> + Unpin, Part> FusedMultipartWrite<Part> for &mut W {
120 fn is_terminated(&self) -> bool {
121 <W as FusedMultipartWrite<Part>>::is_terminated(&**self)
122 }
123}
124
125impl<P, Part> MultipartWrite<Part> for Pin<P>
126where
127 P: DerefMut + Unpin,
128 P::Target: MultipartWrite<Part>,
129{
130 type Ret = <P::Target as MultipartWrite<Part>>::Ret;
131 type Output = <P::Target as MultipartWrite<Part>>::Output;
132 type Error = <P::Target as MultipartWrite<Part>>::Error;
133
134 fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
135 self.get_mut().as_mut().poll_ready(cx)
136 }
137
138 fn start_send(self: Pin<&mut Self>, part: Part) -> Result<Self::Ret, Self::Error> {
139 self.get_mut().as_mut().start_send(part)
140 }
141
142 fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
143 self.get_mut().as_mut().poll_flush(cx)
144 }
145
146 fn poll_complete(
147 self: Pin<&mut Self>,
148 cx: &mut Context<'_>,
149 ) -> Poll<Result<Self::Output, Self::Error>> {
150 self.get_mut().as_mut().poll_complete(cx)
151 }
152}
153
154impl<P, Part> FusedMultipartWrite<Part> for Pin<P>
155where
156 P: DerefMut + Unpin,
157 P::Target: FusedMultipartWrite<Part>,
158{
159 fn is_terminated(&self) -> bool {
160 <P::Target as FusedMultipartWrite<Part>>::is_terminated(&**self)
161 }
162}