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> {
31 Drain {
32 marker: PhantomData,
33 }
34}
35
36impl<T> Unpin for Drain<T> {}
37
38impl<T> Clone for Drain<T> {
39 fn clone(&self) -> Self {
40 drain()
41 }
42}
43
44impl<T> Sink<T> for Drain<T> {
45 type Error = Infallible;
46
47 fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
48 Poll::Ready(Ok(()))
49 }
50
51 fn start_send(self: Pin<&mut Self>, _item: T) -> Result<(), Self::Error> {
52 Ok(())
53 }
54
55 fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
56 Poll::Ready(Ok(()))
57 }
58
59 fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
60 Poll::Ready(Ok(()))
61 }
62}