multipart_write/write/
flush.rs

1use crate::{FusedMultipartWrite, MultipartWrite};
2
3use futures_core::future::{FusedFuture, Future};
4use std::fmt::{self, Debug, Formatter};
5use std::marker::PhantomData;
6use std::pin::Pin;
7use std::task::{Context, Poll};
8
9/// Future for [`flush`](super::MultipartWriteExt::flush).
10#[must_use = "futures do nothing unless polled"]
11pub struct Flush<'a, Wr: ?Sized, Part> {
12    writer: &'a mut Wr,
13    _p: PhantomData<fn(Part)>,
14}
15
16impl<Wr: ?Sized + Unpin, Part> Unpin for Flush<'_, Wr, Part> {}
17
18impl<'a, Wr: ?Sized + MultipartWrite<Part> + Unpin, Part> Flush<'a, Wr, Part> {
19    pub(super) fn new(writer: &'a mut Wr) -> Self {
20        Self {
21            writer,
22            _p: std::marker::PhantomData,
23        }
24    }
25}
26
27impl<Wr, Part> FusedFuture for Flush<'_, Wr, Part>
28where
29    Wr: FusedMultipartWrite<Part> + Unpin,
30{
31    fn is_terminated(&self) -> bool {
32        self.writer.is_terminated()
33    }
34}
35
36impl<Wr: MultipartWrite<Part> + Unpin, Part> Future for Flush<'_, Wr, Part> {
37    type Output = Result<(), Wr::Error>;
38    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
39        Pin::new(&mut self.writer).poll_flush(cx)
40    }
41}
42
43impl<Wr: Debug, Part> Debug for Flush<'_, Wr, Part> {
44    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
45        f.debug_struct("Flush")
46            .field("writer", &self.writer)
47            .finish()
48    }
49}