1 use super::assert_sink;
2 use crate::never::Never;
3 use core::marker::PhantomData;
4 use core::pin::Pin;
5 use futures_core::task::{Context, Poll};
6 use futures_sink::Sink;
7
8 /// Sink for the [`drain`] function.
9 #[derive(Debug)]
10 #[must_use = "sinks do nothing unless polled"]
11 pub struct Drain<T> {
12 marker: PhantomData<T>,
13 }
14
15 /// Create a sink that will just discard all items given to it.
16 ///
17 /// Similar to [`io::Sink`](::std::io::Sink).
18 ///
19 /// # Examples
20 ///
21 /// ```
22 /// # futures::executor::block_on(async {
23 /// use futures::sink::{self, SinkExt};
24 ///
25 /// let mut drain = sink::drain();
26 /// drain.send(5).await?;
27 /// # Ok::<(), futures::never::Never>(()) }).unwrap();
28 /// ```
drain<T>() -> Drain<T>29 pub fn drain<T>() -> Drain<T> {
30 assert_sink::<T, Never, _>(Drain { marker: PhantomData })
31 }
32
33 impl<T> Unpin for Drain<T> {}
34
35 impl<T> Sink<T> for Drain<T> {
36 type Error = Never;
37
poll_ready( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>38 fn poll_ready(
39 self: Pin<&mut Self>,
40 _cx: &mut Context<'_>,
41 ) -> Poll<Result<(), Self::Error>> {
42 Poll::Ready(Ok(()))
43 }
44
start_send( self: Pin<&mut Self>, _item: T, ) -> Result<(), Self::Error>45 fn start_send(
46 self: Pin<&mut Self>,
47 _item: T,
48 ) -> Result<(), Self::Error> {
49 Ok(())
50 }
51
poll_flush( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>52 fn poll_flush(
53 self: Pin<&mut Self>,
54 _cx: &mut Context<'_>,
55 ) -> Poll<Result<(), Self::Error>> {
56 Poll::Ready(Ok(()))
57 }
58
poll_close( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>59 fn poll_close(
60 self: Pin<&mut Self>,
61 _cx: &mut Context<'_>,
62 ) -> Poll<Result<(), Self::Error>> {
63 Poll::Ready(Ok(()))
64 }
65 }
66