Skip to main content

ManualClock

Struct ManualClock 

Source
pub struct ManualClock<P = Timestamp> { /* private fields */ }
Expand description

A clock set and moved by hand, read on one thread.

Reading it costs a load; AtomicManualClock is the one to share across threads. It is not Clone, since a copy would fork time: share it by reference.

§Examples

use t2t_clock::{Clock, ManualClock};
use t2t_core::{Timedelta, Timestamp};

let clock = ManualClock::new(Timestamp::UNIX_EPOCH);
clock.advance(Timedelta::SECOND);
assert_eq!(clock.now(), Timestamp::from_secs(1), "moved on by a second");
clock.set(Timestamp::from_secs(60));
assert_eq!(clock.now(), Timestamp::from_secs(60), "moved to a minute");

Implementations§

Source§

impl<P: TimePoint> ManualClock<P>

Source

pub const fn new(start: P) -> Self

A clock reading start.

Source

pub fn set(&self, point: P)

Moves the clock to point, earlier or later.

Source

pub fn advance(&self, span: P::Span)

Moves the clock by span, back for a negative one, saturating as the point’s addition does.

Trait Implementations§

Source§

impl<P: TimePoint> Clock for ManualClock<P>

Source§

type Reading = P

What the clock reads.
Source§

fn now(&self) -> P

The time now.
Source§

impl<P> Debug for ManualClock<P>
where P: TimePoint + Debug,

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: Default> Default for ManualClock<P>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<P = Timestamp> !Freeze for ManualClock<P>

§

impl<P = Timestamp> !RefUnwindSafe for ManualClock<P>

§

impl<P = Timestamp> !Sync for ManualClock<P>

§

impl<P> Send for ManualClock<P>
where Cell<P>: Send,

§

impl<P> Unpin for ManualClock<P>
where Cell<P>: Unpin,

§

impl<P> UnsafeUnpin for ManualClock<P>
where Cell<P>: UnsafeUnpin,

§

impl<P> UnwindSafe for ManualClock<P>
where Cell<P>: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.