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>
impl<S: Stream> Debounce<S>
Sourcepub fn with_time_getter(
stream: S,
period: Duration,
time_getter: fn() -> Time,
) -> Self
pub fn with_time_getter( stream: S, period: Duration, time_getter: fn() -> Time, ) -> Self
Creates a new Debounce stream with a custom time source.
Sourcepub fn into_inner(self) -> S
pub fn into_inner(self) -> S
Consumes the combinator, returning the underlying stream.
Sourcepub const fn time_getter(&self) -> fn() -> Time
pub const fn time_getter(&self) -> fn() -> Time
Returns the configured time source.
Trait Implementations§
Source§impl<S: Stream> Stream for Debounce<S>
impl<S: Stream> Stream for Debounce<S>
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>
impl<S> Send for Debounce<S>
impl<S> Sync for Debounce<S>
impl<S> UnsafeUnpin for Debounce<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<S> StreamExt for S
impl<S> StreamExt for S
Source§fn next(&mut self) -> Next<'_, Self> ⓘwhere
Self: Unpin,
fn next(&mut self) -> Next<'_, Self> ⓘwhere
Self: Unpin,
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
Source§fn merge(self, other: Self) -> Merge<Self>where
Self: Sized,
fn merge(self, other: Self) -> Merge<Self>where
Self: Sized,
Source§fn zip<S2>(self, other: S2) -> Zip<Self, S2>
fn zip<S2>(self, other: S2) -> Zip<Self, S2>
Source§fn filter<P>(self, predicate: P) -> Filter<Self, P>
fn filter<P>(self, predicate: P) -> Filter<Self, P>
Source§fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
Source§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
Source§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
Source§fn buffered(self, n: usize) -> Buffered<Self>
fn buffered(self, n: usize) -> Buffered<Self>
n futures, preserving output order.Source§fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
n futures, yielding results as they complete.Source§fn chunks(self, size: usize) -> Chunks<Self>where
Self: Sized,
fn chunks(self, size: usize) -> Chunks<Self>where
Self: Sized,
Source§fn ready_chunks(self, size: usize) -> ReadyChunks<Self>where
Self: Sized,
fn ready_chunks(self, size: usize) -> ReadyChunks<Self>where
Self: Sized,
Source§fn fold<Acc, F>(self, init: Acc, f: F) -> Fold<Self, F, Acc> ⓘ
fn fold<Acc, F>(self, init: Acc, f: F) -> Fold<Self, F, Acc> ⓘ
Source§fn for_each_async<F, Fut>(self, f: F) -> ForEachAsync<Self, F, Fut> ⓘ
fn for_each_async<F, Fut>(self, f: F) -> ForEachAsync<Self, F, Fut> ⓘ
Source§fn try_collect<T, E, C>(self) -> TryCollect<Self, C> ⓘ
fn try_collect<T, E, C>(self) -> TryCollect<Self, C> ⓘ
Source§fn try_fold<T, E, Acc, F>(self, init: Acc, f: F) -> TryFold<Self, F, Acc> ⓘ
fn try_fold<T, E, Acc, F>(self, init: Acc, f: F) -> TryFold<Self, F, Acc> ⓘ
Source§fn try_for_each<F, E>(self, f: F) -> TryForEach<Self, F> ⓘ
fn try_for_each<F, E>(self, f: F) -> TryForEach<Self, F> ⓘ
Source§fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
Iterator::scan. Read more