|
| 1 | +mod flush; |
| 2 | +mod write_all; |
| 3 | +mod write; |
| 4 | +mod write_vectored; |
| 5 | + |
| 6 | +use flush::FlushFuture; |
| 7 | +use write_all::WriteAllFuture; |
| 8 | +use write::WriteFuture; |
| 9 | +use write_vectored::WriteVectoredFuture; |
| 10 | + |
1 | 11 | use std::io::IoSlice; |
2 | | -use std::mem; |
3 | | -use std::pin::Pin; |
4 | 12 |
|
5 | 13 | use cfg_if::cfg_if; |
6 | 14 | use futures_io::AsyncWrite; |
7 | 15 |
|
8 | | -use crate::future::Future; |
9 | | -use crate::io; |
10 | | -use crate::task::{Context, Poll}; |
11 | | - |
12 | 16 | cfg_if! { |
13 | 17 | if #[cfg(feature = "docs")] { |
14 | 18 | #[doc(hidden)] |
@@ -140,76 +144,3 @@ impl<T: AsyncWrite + Unpin + ?Sized> Write for T { |
140 | 144 | FlushFuture { writer: self } |
141 | 145 | } |
142 | 146 | } |
143 | | - |
144 | | -#[doc(hidden)] |
145 | | -#[allow(missing_debug_implementations)] |
146 | | -pub struct WriteFuture<'a, T: Unpin + ?Sized> { |
147 | | - writer: &'a mut T, |
148 | | - buf: &'a [u8], |
149 | | -} |
150 | | - |
151 | | -impl<T: AsyncWrite + Unpin + ?Sized> Future for WriteFuture<'_, T> { |
152 | | - type Output = io::Result<usize>; |
153 | | - |
154 | | - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
155 | | - let buf = self.buf; |
156 | | - Pin::new(&mut *self.writer).poll_write(cx, buf) |
157 | | - } |
158 | | -} |
159 | | - |
160 | | -#[doc(hidden)] |
161 | | -#[allow(missing_debug_implementations)] |
162 | | -pub struct FlushFuture<'a, T: Unpin + ?Sized> { |
163 | | - writer: &'a mut T, |
164 | | -} |
165 | | - |
166 | | -impl<T: AsyncWrite + Unpin + ?Sized> Future for FlushFuture<'_, T> { |
167 | | - type Output = io::Result<()>; |
168 | | - |
169 | | - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
170 | | - Pin::new(&mut *self.writer).poll_flush(cx) |
171 | | - } |
172 | | -} |
173 | | - |
174 | | -#[doc(hidden)] |
175 | | -#[allow(missing_debug_implementations)] |
176 | | -pub struct WriteVectoredFuture<'a, T: Unpin + ?Sized> { |
177 | | - writer: &'a mut T, |
178 | | - bufs: &'a [IoSlice<'a>], |
179 | | -} |
180 | | - |
181 | | -impl<T: AsyncWrite + Unpin + ?Sized> Future for WriteVectoredFuture<'_, T> { |
182 | | - type Output = io::Result<usize>; |
183 | | - |
184 | | - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
185 | | - let bufs = self.bufs; |
186 | | - Pin::new(&mut *self.writer).poll_write_vectored(cx, bufs) |
187 | | - } |
188 | | -} |
189 | | - |
190 | | -#[doc(hidden)] |
191 | | -#[allow(missing_debug_implementations)] |
192 | | -pub struct WriteAllFuture<'a, T: Unpin + ?Sized> { |
193 | | - writer: &'a mut T, |
194 | | - buf: &'a [u8], |
195 | | -} |
196 | | - |
197 | | -impl<T: AsyncWrite + Unpin + ?Sized> Future for WriteAllFuture<'_, T> { |
198 | | - type Output = io::Result<()>; |
199 | | - |
200 | | - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
201 | | - let Self { writer, buf } = &mut *self; |
202 | | - |
203 | | - while !buf.is_empty() { |
204 | | - let n = futures_core::ready!(Pin::new(&mut **writer).poll_write(cx, buf))?; |
205 | | - let (_, rest) = mem::replace(buf, &[]).split_at(n); |
206 | | - *buf = rest; |
207 | | - |
208 | | - if n == 0 { |
209 | | - return Poll::Ready(Err(io::ErrorKind::WriteZero.into())); |
210 | | - } |
211 | | - } |
212 | | - |
213 | | - Poll::Ready(Ok(())) |
214 | | - } |
215 | | -} |
0 commit comments