futures_util/sink/
drain.rs1use 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> Sink<T> for Drain<T> {
36 type Error = Never;
37
38 fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
39 Poll::Ready(Ok(()))
40 }
41
42 fn start_send(self: Pin<&mut Self>, _item: T) -> Result<(), Self::Error> {
43 Ok(())
44 }
45
46 fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
47 Poll::Ready(Ok(()))
48 }
49
50 fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
51 Poll::Ready(Ok(()))
52 }
53}