#[repr(transparent)]pub struct Timestamp<T = u64>(pub T);
Expand description
Timestamp
is a generic implementation of a type that represents some point in time.
§Usage
§Examples
§Example #1 Using the now
method to get the current timestamp
#[cfg(feature = "std")]
let ts = scsys_core::Timestamp::<u64>::now();
§Features
The timestamps implementation dynamically reflects the extensive feature-gating of the
crate. Listed below are the features that customize the behavior of the Timestamp
type:
Tuple Fields§
§0: T
Implementations§
Source§impl<T> Timestamp<T>where
T: RawTimestamp,
impl<T> Timestamp<T>where
T: RawTimestamp,
Sourcepub fn now() -> Selfwhere
Self: Now<Output = Self>,
pub fn now() -> Selfwhere
Self: Now<Output = Self>,
a convenience method to create a new Timestamp
instance with the current time.
Sourcepub const fn replace(&mut self, value: T) -> T
pub const fn replace(&mut self, value: T) -> T
replace
the current value with a new one and return the old one
Sourcepub fn set(&mut self, ts: T) -> &mut Self
pub fn set(&mut self, ts: T) -> &mut Self
update the current value and return a mutable reference to the current instance.
Sourcepub const fn swap(&mut self, ts: &mut T)
pub const fn swap(&mut self, ts: &mut T)
swap
the current value with another and return a mutable reference to self
Sourcepub fn with<U: RawTimestamp>(self, ts: U) -> Timestamp<U>
pub fn with<U: RawTimestamp>(self, ts: U) -> Timestamp<U>
consumes the current instance to create another with the given value
Sourcepub fn map<U, F>(self, f: F) -> Timestamp<U>where
F: FnOnce(T) -> U,
U: RawTimestamp,
pub fn map<U, F>(self, f: F) -> Timestamp<U>where
F: FnOnce(T) -> U,
U: RawTimestamp,
applies a function onto the current value and returns a new instance with the result
Sourcepub fn map_inplace<F>(&mut self, f: F) -> &mut Self
pub fn map_inplace<F>(&mut self, f: F) -> &mut Self
returns a new instance of the Timestamp
with the current value updated using the given function
Sourcepub fn update(&mut self) -> Twhere
T: Now<Output = T>,
pub fn update(&mut self) -> Twhere
T: Now<Output = T>,
updates the timestamp to reflect now and return the previous timestamp
Source§impl<T> Timestamp<T>where
T: RawTimestamp,
impl<T> Timestamp<T>where
T: RawTimestamp,
Trait Implementations§
Source§impl<T: RawTimestamp> AsMut<T> for Timestamp<T>
impl<T: RawTimestamp> AsMut<T> for Timestamp<T>
Source§impl<T: RawTimestamp> AsRef<T> for Timestamp<T>
impl<T: RawTimestamp> AsRef<T> for Timestamp<T>
Source§impl<T: RawTimestamp> Borrow<T> for Timestamp<T>
impl<T: RawTimestamp> Borrow<T> for Timestamp<T>
Source§impl<T: RawTimestamp> BorrowMut<T> for Timestamp<T>
impl<T: RawTimestamp> BorrowMut<T> for Timestamp<T>
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T: RawTimestamp> Deref for Timestamp<T>
impl<T: RawTimestamp> Deref for Timestamp<T>
Source§impl<T: RawTimestamp> DerefMut for Timestamp<T>
impl<T: RawTimestamp> DerefMut for Timestamp<T>
Source§impl<'de, T> Deserialize<'de> for Timestamp<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Timestamp<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: Ord> Ord for Timestamp<T>
impl<T: Ord> Ord for Timestamp<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd> PartialOrd for Timestamp<T>
impl<T: PartialOrd> PartialOrd for Timestamp<T>
impl<T: Copy> Copy for Timestamp<T>
impl<T: Eq> Eq for Timestamp<T>
impl<T> StructuralPartialEq for Timestamp<T>
Auto Trait Implementations§
impl<T> Freeze for Timestamp<T>where
T: Freeze,
impl<T> RefUnwindSafe for Timestamp<T>where
T: RefUnwindSafe,
impl<T> Send for Timestamp<T>where
T: Send,
impl<T> Sync for Timestamp<T>where
T: Sync,
impl<T> Unpin for Timestamp<T>where
T: Unpin,
impl<T> UnwindSafe for Timestamp<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<K, S> Identity<K> for Swhere
S: Borrow<K>,
K: Identifier,
impl<K, S> Identity<K> for Swhere
S: Borrow<K>,
K: Identifier,
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform
distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p
of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator
of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
random
to avoid conflict with the new gen
keyword in Rust 2024.Rng::random
.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
random_range
Rng::random_range
.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32
.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64
.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest
entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
UnwrapMut
wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
RngCore
to a RngReadAdapter
.