[][src]Struct rjdebounce::Bouncer

pub struct Bouncer<T> {
    pub delay: Duration,
    // some fields omitted
}

Fields

delay: Duration

Implementations

impl<T> Bouncer<T>[src]

pub fn new(delay: Duration) -> Self[src]

Creates a new bouncer object

Example Usage:

    use rjdebounce::Bouncer;
 
    let mut bouncer = Bouncer::new(Duration::from_secs(1));
 
    let result = bouncer.debounce(|| {
        return 5 + 5;
    })
  
    assert_eq!(result.is_some(), true);
    assert_eq!(result.unwrap(), 10);

pub fn with_func(self, func: fn() -> T) -> Self[src]

Binds a function internally to call using the execute() function.

Example Usage:

    use rjdebounce::Bouncer;
 
    let mut bouncer = Bouncer::new(Duration::from_secs(1)).with_func(|| 5 + 5);
     
    let result1 = bouncer.get_result();
    bouncer.execute();
    let result2 = bouncer.get_result();
 
    assert_equal!(result.is_some(), false);
    assert_equal!(result.is_some(), true);

pub fn execute(&mut self)[src]

If Bouncer is created with_func(), call this function to execute the provided function.

pub fn get_result(&mut self) -> Option<&mut T>[src]

If Bouncer is created with_func(), call this function in order to obtain a reference to the result.

pub fn debounce(&mut self, func: fn() -> T) -> Option<T>[src]

debounces provided function only running if it has never been run, or, if the elasped time has past since the function was last run.

pub fn reset(&mut self)[src]

Resets the last_run property to None. Makes the bouncer act as if it never ran a function.

Auto Trait Implementations

impl<T> RefUnwindSafe for Bouncer<T> where
    T: RefUnwindSafe

impl<T> Send for Bouncer<T> where
    T: Send

impl<T> Sync for Bouncer<T> where
    T: Sync

impl<T> Unpin for Bouncer<T> where
    T: Unpin

impl<T> UnwindSafe for Bouncer<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.