1#![cfg_attr(docsrs, feature(doc_cfg))]
11use std::ops::{Deref, 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 trait FusedMultipartWrite<Part>: MultipartWrite<Part> {
81 fn is_terminated(&self) -> bool;
83}
84
85impl<W: ?Sized + MultipartWrite<Part> + Unpin, Part> MultipartWrite<Part> for &mut W {
86 type Ret = W::Ret;
87 type Output = W::Output;
88 type Error = W::Error;
89
90 fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
91 Pin::new(&mut **self).poll_ready(cx)
92 }
93
94 fn start_send(mut self: Pin<&mut Self>, part: Part) -> Result<Self::Ret, Self::Error> {
95 Pin::new(&mut **self).start_send(part)
96 }
97
98 fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
99 Pin::new(&mut **self).poll_flush(cx)
100 }
101
102 fn poll_complete(
103 mut self: Pin<&mut Self>,
104 cx: &mut Context<'_>,
105 ) -> Poll<Result<Self::Output, Self::Error>> {
106 Pin::new(&mut **self).poll_complete(cx)
107 }
108}
109
110impl<W: ?Sized + FusedMultipartWrite<Part> + Unpin, Part> FusedMultipartWrite<Part> for &mut W {
111 fn is_terminated(&self) -> bool {
112 W::is_terminated(self)
113 }
114}
115
116impl<P, Part> MultipartWrite<Part> for Pin<P>
117where
118 P: DerefMut + Unpin,
119 P::Target: MultipartWrite<Part>,
120{
121 type Ret = <P::Target as MultipartWrite<Part>>::Ret;
122 type Output = <P::Target as MultipartWrite<Part>>::Output;
123 type Error = <P::Target as MultipartWrite<Part>>::Error;
124
125 fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
126 self.get_mut().as_mut().poll_ready(cx)
127 }
128
129 fn start_send(self: Pin<&mut Self>, part: Part) -> Result<Self::Ret, Self::Error> {
130 self.get_mut().as_mut().start_send(part)
131 }
132
133 fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
134 self.get_mut().as_mut().poll_flush(cx)
135 }
136
137 fn poll_complete(
138 self: Pin<&mut Self>,
139 cx: &mut Context<'_>,
140 ) -> Poll<Result<Self::Output, Self::Error>> {
141 self.get_mut().as_mut().poll_complete(cx)
142 }
143}
144
145impl<P, Part> FusedMultipartWrite<Part> for Pin<P>
146where
147 P: DerefMut + Unpin,
148 P::Target: FusedMultipartWrite<Part>,
149{
150 fn is_terminated(&self) -> bool {
151 self.deref().is_terminated()
152 }
153}