Skip to main content

AtomicManualClock

Struct AtomicManualClock 

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

A clock set and moved by hand, shared across threads.

A thread that reads a point another set or moved the clock to also sees what that thread wrote before. It is not Clone, since a copy would fork time: share it by reference or Arc.

§Examples

use std::thread;

use t2t_clock::{AtomicManualClock, Clock};
use t2t_core::{Timedelta, Uptime};

let clock = AtomicManualClock::new(Uptime::from_secs(1));
thread::scope(|scope| {
    scope.spawn(|| clock.advance(Timedelta::SECOND));
});
assert_eq!(clock.now(), Uptime::from_secs(2), "the other thread's move");

Implementations§

Source§

impl<P: TimePoint> AtomicManualClock<P>

Source

pub 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 AtomicManualClock<P>

Source§

type Reading = P

What the clock reads.
Source§

fn now(&self) -> P

The time now.
Source§

impl<P> Debug for AtomicManualClock<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: TimePoint + Default> Default for AtomicManualClock<P>

By hand, since a derived one would start the count at zero, not at the point’s default.

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

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

§

impl<P> RefUnwindSafe for AtomicManualClock<P>
where PhantomData<fn() -> P>: RefUnwindSafe,

§

impl<P> Send for AtomicManualClock<P>
where PhantomData<fn() -> P>: Send,

§

impl<P> Sync for AtomicManualClock<P>
where PhantomData<fn() -> P>: Sync,

§

impl<P> Unpin for AtomicManualClock<P>
where PhantomData<fn() -> P>: Unpin,

§

impl<P> UnsafeUnpin for AtomicManualClock<P>
where PhantomData<fn() -> P>: UnsafeUnpin,

§

impl<P> UnwindSafe for AtomicManualClock<P>
where PhantomData<fn() -> 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.