pub struct ScopedSleep { /* private fields */ }
Expand description
RAII sleep
Implementations§
Source§impl ScopedSleep
impl ScopedSleep
Sourcepub fn new(sleep_duration: Duration) -> Self
pub fn new(sleep_duration: Duration) -> Self
Create sleep
§Example
let now = std::time::Instant::now();
{
// Do not use `let _ = ..` here because it immediately drops ScopedSleep.
let _guard = scoped_sleep::ScopedSleep::new(std::time::Duration::from_millis(100));
// not sleep yet
assert!(now.elapsed() < std::time::Duration::from_millis(20));
}
// slept
assert!(now.elapsed() > std::time::Duration::from_millis(20));
Sourcepub fn from_secs(sleep_duration_sec: f64) -> Self
pub fn from_secs(sleep_duration_sec: f64) -> Self
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 = scoped_sleep::ScopedSleep::from_secs(0.1);
// not sleep yet
assert!(now.elapsed() < std::time::Duration::from_millis(10));
}
// slept
assert!(now.elapsed() > std::time::Duration::from_millis(10));
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ScopedSleep
impl RefUnwindSafe for ScopedSleep
impl Send for ScopedSleep
impl Sync for ScopedSleep
impl Unpin for ScopedSleep
impl UnwindSafe for ScopedSleep
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