From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/futures-util/src/stream/empty.rs | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 third_party/rust/futures-util/src/stream/empty.rs (limited to 'third_party/rust/futures-util/src/stream/empty.rs') diff --git a/third_party/rust/futures-util/src/stream/empty.rs b/third_party/rust/futures-util/src/stream/empty.rs new file mode 100644 index 0000000000..e4fd87326b --- /dev/null +++ b/third_party/rust/futures-util/src/stream/empty.rs @@ -0,0 +1,45 @@ +use super::assert_stream; +use core::marker::PhantomData; +use core::pin::Pin; +use futures_core::stream::{FusedStream, Stream}; +use futures_core::task::{Context, Poll}; + +/// Stream for the [`empty`] function. +#[derive(Debug)] +#[must_use = "streams do nothing unless polled"] +pub struct Empty { + _phantom: PhantomData, +} + +/// Creates a stream which contains no elements. +/// +/// The returned stream will always return `Ready(None)` when polled. +pub fn empty() -> Empty { + assert_stream::(Empty { _phantom: PhantomData }) +} + +impl Unpin for Empty {} + +impl FusedStream for Empty { + fn is_terminated(&self) -> bool { + true + } +} + +impl Stream for Empty { + type Item = T; + + fn poll_next(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { + Poll::Ready(None) + } + + fn size_hint(&self) -> (usize, Option) { + (0, Some(0)) + } +} + +impl Clone for Empty { + fn clone(&self) -> Self { + empty() + } +} -- cgit v1.2.3