futures_util/sink/
drain.rs
1use super::assert_sink;
2use crate::never::Never;
3use core::marker::PhantomData;
4use core::pin::Pin;
5use futures_core::task::{Context, Poll};
6use futures_sink::Sink;
7
8#[derive(Debug)]
10#[must_use = "sinks do nothing unless polled"]
11pub struct Drain<T> {
12 marker: PhantomData<T>,
13}
14
15pub fn drain<T>() -> Drain<T> {
30 assert_sink::<T, Never, _>(Drain { marker: PhantomData })
31}
32
33impl<T> Unpin for Drain<T> {}
34
35impl<T> Clone for Drain<T> {
36 fn clone(&self) -> Self {
37 drain()
38 }
39}
40
41impl<T> Sink<T> for Drain<T> {
42 type Error = Never;
43
44 fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
45 Poll::Ready(Ok(()))
46 }
47
48 fn start_send(self: Pin<&mut Self>, _item: T) -> Result<(), Self::Error> {
49 Ok(())
50 }
51
52 fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
53 Poll::Ready(Ok(()))
54 }
55
56 fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
57 Poll::Ready(Ok(()))
58 }
59}