pub struct Guard<'sw, I: Instant> { /* private fields */ }Expand description
A running, guarded, stopwatch. When dropped, the stopwatch will automatically stop.
Guards are returned by the StopwatchImpl methods
guard and guard_at.
§Examples
let mut sw = Sw::new();
{
let _guard = sw.guard()?;
// stopwatch is now running and guarded!
thread::sleep(Duration::from_millis(100));
// guard dropped, stopwatch stopped
}
assert!(sw.is_stopped());
assert!(sw.elapsed() >= Duration::from_millis(100));Implementations§
Source§impl<'sw, I: Instant> Guard<'sw, I>
impl<'sw, I: Instant> Guard<'sw, I>
Sourcepub fn new(sw: &'sw mut StopwatchImpl<I>) -> Result<Self>
pub fn new(sw: &'sw mut StopwatchImpl<I>) -> Result<Self>
Sourcepub const fn inner(&self) -> &StopwatchImpl<I>
pub const fn inner(&self) -> &StopwatchImpl<I>
Returns a reference to the inner StopwatchImpl.
§Examples
let mut sw = Sw::new();
let guard = sw.guard()?;
thread::sleep(Duration::from_millis(100));
assert!(guard.inner().elapsed() >= Duration::from_millis(100));Trait Implementations§
impl<I: Instant> Eq for Guard<'_, I>
Auto Trait Implementations§
impl<'sw, I> Freeze for Guard<'sw, I>
impl<'sw, I> RefUnwindSafe for Guard<'sw, I>where
I: RefUnwindSafe,
impl<'sw, I> Send for Guard<'sw, I>where
I: Send,
impl<'sw, I> Sync for Guard<'sw, I>where
I: Sync,
impl<'sw, I> Unpin for Guard<'sw, I>
impl<'sw, I> !UnwindSafe for Guard<'sw, I>
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