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