Struct openrr_sleep::ScopedSleep[][src]

pub struct ScopedSleep { /* fields omitted */ }
Expand description

RAII sleep

Implementations

Create sleep

Example

let now = std::time::Instant::now();
{
    // Do not use `let _ = ..` here because it immediately drops ScopedSleep.
    let _guard = openrr_sleep::ScopedSleep::new(std::time::Duration::from_millis(100));
    // not sleep yet
    assert!(now.elapsed() < std::time::Duration::from_millis(20));
}
// sleeped
assert!(now.elapsed() > std::time::Duration::from_millis(20));

Create sleep from float secs value

Example

let now = std::time::Instant::now();
{
    // Do not use `let _ = ..` here because it immediately drops ScopedSleep.
    let _guard = openrr_sleep::ScopedSleep::from_secs(0.1);
    // not sleep yet
    assert!(now.elapsed() < std::time::Duration::from_millis(10));
}
// sleeped
assert!(now.elapsed() > std::time::Duration::from_millis(10));

Trait Implementations

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.