pub struct DebouncerWithClock<C: Clock> { /* private fields */ }Expand description
A debouncer with pluggable clock for testing
Like Debouncer, but uses a Clock trait for time access,
enabling deterministic testing with FakeClock.
§Example
ⓘ
use egui_cha::testing::FakeClock;
use egui_cha::helpers::DebouncerWithClock;
use std::time::Duration;
let clock = FakeClock::new();
let mut debouncer = DebouncerWithClock::new(clock.clone());
debouncer.trigger(Duration::from_millis(500), Msg::Search);
assert!(!debouncer.should_fire()); // Not yet
clock.advance(Duration::from_millis(600));
assert!(debouncer.should_fire()); // Now it firesImplementations§
Source§impl<C: Clock> DebouncerWithClock<C>
impl<C: Clock> DebouncerWithClock<C>
Sourcepub fn mark_trigger(&mut self, delay: Duration)
pub fn mark_trigger(&mut self, delay: Duration)
Mark trigger time without returning a Cmd
Use this when you want to manage the delay yourself.
Call should_fire() after the delay to check if it should fire.
Sourcepub fn should_fire(&mut self) -> bool
pub fn should_fire(&mut self) -> bool
Check if the debounced action should fire
Returns true if enough time has passed since the last trigger() call.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Check if there’s a pending debounce
Trait Implementations§
Source§impl<C: Clone + Clock> Clone for DebouncerWithClock<C>
impl<C: Clone + Clock> Clone for DebouncerWithClock<C>
Source§fn clone(&self) -> DebouncerWithClock<C>
fn clone(&self) -> DebouncerWithClock<C>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<C> Freeze for DebouncerWithClock<C>where
C: Freeze,
impl<C> RefUnwindSafe for DebouncerWithClock<C>where
C: RefUnwindSafe,
impl<C> Send for DebouncerWithClock<C>where
C: Send,
impl<C> Sync for DebouncerWithClock<C>where
C: Sync,
impl<C> Unpin for DebouncerWithClock<C>where
C: Unpin,
impl<C> UnwindSafe for DebouncerWithClock<C>where
C: UnwindSafe,
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
Mutably borrows from an owned value. Read more