Skip to main content

ScriptedTimer

Struct ScriptedTimer 

Source
pub struct ScriptedTimer(/* private fields */);
Expand description

The app’s clock for a test that pins a deadline without waiting for it: no sleep it hands out ends until advance has moved the clock past it. Each live sleep is counted by its length, so a test asks whether the code under test is waiting on a deadline of a given length (live) and whether it stopped waiting. A length named to refuse is timed as a runtime that has shut down times it.

Implementations§

Source§

impl ScriptedTimer

Source

pub fn new() -> ScriptedTimer

A clock at zero with no sleeps live and nothing refused.

Source

pub fn advance(&self, by: Duration)

Moves the clock forward and wakes every sleep waiting on it; one whose deadline is now behind the clock ends on its next poll.

Source

pub fn live(&self, length: Duration) -> usize

The sleeps of exactly length that exist and have not been dropped.

Source

pub fn pending_at(&self, length: Duration) -> Option<Duration>

The clock time, as elapsed reads it, at which a sleep of exactly length last answered Pending; None if none has. A value equal to elapsed() means the sleep has seen the latest advance and not ended on it: a test waits on that to know the code under test observed the clock short of its deadline.

Source

pub fn refuse(&self, length: Duration)

From this call on, a sleep of exactly length is answered as a runtime that has shut down answers it: sleep ends at once and try_sleep answers Err(Refused). Other lengths keep their script, so a bound of another length the code under test also arms stays pending.

Source

pub fn refused(&self, length: Duration) -> usize

The sleeps of exactly length, sleep and try_sleep alike, asked of the clock since refuse named it. A loop that paces itself on try_sleep and ends on a refusal asks once; one that ignores the refusal asks again on every turn.

Source

pub fn elapsed(&self) -> Duration

How far the clock has been advanced since it was made.

Trait Implementations§

Source§

impl Clone for ScriptedTimer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for ScriptedTimer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Timer for ScriptedTimer

Source§

fn sleep(&self, d: Duration) -> BoxFuture<'static, ()>

Ends once d has passed, or at once on a clock whose runtime has shut down, before the sleep or during it. try_sleep tells the two ends apart.
Source§

fn now(&self) -> Instant

Source§

fn try_sleep(&self, d: Duration) -> BoxFuture<'static, Result<(), Refused>>

sleep, answering Err(Refused) when the clock’s runtime has shut down, before the sleep or during it. Code that would otherwise act on a deadline it can no longer keep reads this. A clock that cannot shut down answers sleep’s end as Ok. A wrapper forwards this to the clock it wraps, as it forwards sleep: answering Ok there drops that clock’s refusal.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more