Skip to main content

Debounce

Struct Debounce 

Source
pub struct Debounce<S: Stream> { /* private fields */ }
Expand description

A stream that debounces items, emitting only after a quiet period.

Created by StreamExt::debounce.

When the underlying stream produces an item, it is buffered. If no new item arrives for period, the buffered item is yielded. Each new item replaces the buffered value and resets the timer.

When the underlying stream ends, any buffered item is flushed immediately.

§Note

By default this combinator uses the runtime wall clock via crate::time::wall_now, but tests and adapters can override that with Debounce::with_time_getter. The combinator still arms an internal Sleep so the executor gets a real wakeup when the quiet period expires, while readiness decisions continue to use the configured time getter.

Implementations§

Source§

impl<S: Stream> Debounce<S>

Source

pub fn with_time_getter( stream: S, period: Duration, time_getter: fn() -> Time, ) -> Self

Creates a new Debounce stream with a custom time source.

Source

pub fn get_ref(&self) -> &S

Returns a reference to the underlying stream.

Source

pub fn get_mut(&mut self) -> &mut S

Returns a mutable reference to the underlying stream.

Source

pub fn into_inner(self) -> S

Consumes the combinator, returning the underlying stream.

Source

pub const fn time_getter(&self) -> fn() -> Time

Returns the configured time source.

Trait Implementations§

Source§

impl<S: Stream + Debug> Debug for Debounce<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Stream> Stream for Debounce<S>

Source§

type Item = <S as Stream>::Item

The type of values yielded by the stream.
Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<S::Item>>

Attempt to pull out the next value of this stream. Read more
Source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more
Source§

impl<'pin, S: Stream> Unpin for Debounce<S>
where PinnedFieldsOf<__Debounce<'pin, S>>: Unpin,

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for Debounce<S>

§

impl<S> !UnwindSafe for Debounce<S>

§

impl<S> Freeze for Debounce<S>
where S: Freeze, <S as Stream>::Item: Freeze,

§

impl<S> Send for Debounce<S>
where S: Send, <S as Stream>::Item: Send,

§

impl<S> Sync for Debounce<S>
where S: Sync, <S as Stream>::Item: Sync,

§

impl<S> UnsafeUnpin for Debounce<S>
where S: UnsafeUnpin, <S as Stream>::Item: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<S> StreamExt for S
where S: Stream + ?Sized,

Source§

fn next(&mut self) -> Next<'_, Self>
where Self: Unpin,

Returns the next item from the stream.
Source§

fn map<T, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> T,

Transforms each item using a closure.
Source§

fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
where Self: Sized, F: FnMut(Self::Item) -> Fut, Fut: Future,

Transforms each item using an async closure.
Source§

fn chain<S2>(self, other: S2) -> Chain<Self, S2>
where Self: Sized, S2: Stream<Item = Self::Item>,

Chains this stream with another stream.
Source§

fn merge(self, other: Self) -> Merge<Self>
where Self: Sized,

Interleaves this stream with another stream of the same concrete type. Read more
Source§

fn zip<S2>(self, other: S2) -> Zip<Self, S2>
where Self: Sized, S2: Stream,

Zips this stream with another stream, yielding pairs.
Source§

fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Yields only items that match the predicate.
Source§

fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Option<T>,

Filters and transforms items in one step.
Source§

fn take(self, n: usize) -> Take<Self>
where Self: Sized,

Takes the first n items.
Source§

fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Takes items while the predicate is true.
Source§

fn skip(self, n: usize) -> Skip<Self>
where Self: Sized,

Skips the first n items.
Source§

fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Skips items while the predicate is true.
Source§

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Enumerates items with their index.
Source§

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Fuses the stream to handle None gracefully.
Source§

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where Self: Sized, F: FnMut(&Self::Item),

Inspects items without modifying the stream.
Source§

fn buffered(self, n: usize) -> Buffered<Self>
where Self: Sized, Self::Item: Future,

Buffers up to n futures, preserving output order.
Source§

fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
where Self: Sized, Self::Item: Future,

Buffers up to n futures, yielding results as they complete.
Source§

fn collect<C>(self) -> Collect<Self, C>
where Self: Sized, C: Default + Extend<Self::Item>,

Collects all items into a collection.
Source§

fn chunks(self, size: usize) -> Chunks<Self>
where Self: Sized,

Collects items into fixed-size chunks.
Source§

fn ready_chunks(self, size: usize) -> ReadyChunks<Self>
where Self: Sized,

Yields immediately available items up to a maximum chunk size.
Source§

fn fold<Acc, F>(self, init: Acc, f: F) -> Fold<Self, F, Acc>
where Self: Sized, F: FnMut(Acc, Self::Item) -> Acc,

Folds all items into a single value.
Source§

fn for_each<F>(self, f: F) -> ForEach<Self, F>
where Self: Sized, F: FnMut(Self::Item),

Executes a closure for each item.
Source§

fn for_each_async<F, Fut>(self, f: F) -> ForEachAsync<Self, F, Fut>
where Self: Sized, F: FnMut(Self::Item) -> Fut, Fut: Future<Output = ()>,

Executes an async closure for each item.
Source§

fn count(self) -> Count<Self>
where Self: Sized,

Counts the number of items in the stream.
Source§

fn any<P>(self, predicate: P) -> Any<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Checks if any item matches the predicate.
Source§

fn all<P>(self, predicate: P) -> All<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Checks if all items match the predicate.
Source§

fn try_collect<T, E, C>(self) -> TryCollect<Self, C>
where Self: Stream<Item = Result<T, E>> + Sized, C: Default + Extend<T>,

Collects items from a stream of Results, short-circuiting on error.
Source§

fn try_fold<T, E, Acc, F>(self, init: Acc, f: F) -> TryFold<Self, F, Acc>
where Self: Stream<Item = Result<T, E>> + Sized, F: FnMut(Acc, T) -> Result<Acc, E>,

Folds a stream of Results, short-circuiting on error.
Source§

fn try_for_each<F, E>(self, f: F) -> TryForEach<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Result<(), E>,

Executes a fallible closure for each item, short-circuiting on error.
Source§

fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
where Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B>,

Yields intermediate accumulator values, like Iterator::scan. Read more
Source§

fn peekable(self) -> Peekable<Self>
where Self: Sized,

Creates a peekable stream that supports looking at the next item without consuming it.
Source§

fn throttle(self, period: Duration) -> Throttle<Self>
where Self: Sized,

Rate-limits the stream to at most one item per period. Read more
Source§

fn debounce(self, period: Duration) -> Debounce<Self>
where Self: Sized, Self::Item: Unpin,

Debounces the stream, emitting only after a quiet period. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V