#[repr(transparent)]pub struct Timestamp<T = u128>(pub T);
Expand description
Timestamp
is a generic implementation of a type that represents some point in time.
§Basic Usage
use scsys_time::Timestamp;
let ts = Timestamp::<u128>::now();
println!("Current Timestamp: {}", ts);
§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 const fn new(ts: T) -> Timestamp<T>
pub const fn new(ts: T) -> Timestamp<T>
create a new instance of Timestamp
with the given value.
Sourcepub fn now() -> Timestamp<T>
pub fn now() -> Timestamp<T>
a convenience method to get the current timestamp; requires that the inner type
implement the Now
trait.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
consumes the current instance and returns the inner value.
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)
pub fn set(&mut self, ts: T)
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>(self, ts: U) -> Timestamp<U>where
U: RawTimestamp,
pub fn with<U>(self, ts: U) -> Timestamp<U>where
U: RawTimestamp,
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 Timestamp<T>
pub fn map_inplace<F>(&mut self, f: F) -> &mut Timestamp<T>
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> BorrowMut<T> for Timestamp<T>
impl<T> BorrowMut<T> for Timestamp<T>
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut 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<Timestamp<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Timestamp<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<T> Ord for Timestamp<T>where
T: Ord,
impl<T> Ord for Timestamp<T>where
T: Ord,
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T> PartialOrd for Timestamp<T>where
T: PartialOrd,
impl<T> PartialOrd for Timestamp<T>where
T: PartialOrd,
Source§impl<T> Serialize for Timestamp<T>where
T: Serialize,
impl<T> Serialize for Timestamp<T>where
T: Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl<T> TimestampRepr for Timestamp<T>where
T: RawTimestamp,
impl<T> TimestampRepr for Timestamp<T>where
T: RawTimestamp,
impl<T> Copy for Timestamp<T>where
T: Copy,
impl<T> Eq for Timestamp<T>where
T: Eq,
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
.