futures_util/io/
sink.rs
1use futures_core::task::{Context, Poll};
2use futures_io::{AsyncWrite, IoSlice};
3use std::fmt;
4use std::io;
5use std::pin::Pin;
6
7#[must_use = "writers do nothing unless polled"]
9pub struct Sink {
10 _priv: (),
11}
12
13pub fn sink() -> Sink {
31 Sink { _priv: () }
32}
33
34impl AsyncWrite for Sink {
35 #[inline]
36 fn poll_write(
37 self: Pin<&mut Self>,
38 _: &mut Context<'_>,
39 buf: &[u8],
40 ) -> Poll<io::Result<usize>> {
41 Poll::Ready(Ok(buf.len()))
42 }
43
44 #[inline]
45 fn poll_write_vectored(
46 self: Pin<&mut Self>,
47 _: &mut Context<'_>,
48 bufs: &[IoSlice<'_>],
49 ) -> Poll<io::Result<usize>> {
50 Poll::Ready(Ok(bufs.iter().map(|b| b.len()).sum()))
51 }
52
53 #[inline]
54 fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
55 Poll::Ready(Ok(()))
56 }
57 #[inline]
58 fn poll_close(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
59 Poll::Ready(Ok(()))
60 }
61}
62
63impl fmt::Debug for Sink {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 f.pad("Sink { .. }")
66 }
67}