#[repr(transparent)]pub struct Id<T = usize>(pub T);
Expand description
Id
is a generic identifier type that wraps a value of type T
.
Tuple Fields§
§0: T
Implementations§
Source§impl<T> Id<T>
impl<T> Id<T>
pub fn random() -> Selfwhere
StandardUniform: Distribution<T>,
Sourcepub const fn replace(&mut self, id: T) -> T
pub const fn replace(&mut self, id: T) -> T
use the replace
method to update and return the inner value
Sourcepub fn set(&mut self, id: T) -> &mut Self
pub fn set(&mut self, id: T) -> &mut Self
mutate the inner value and return a mutable reference to the wrapper for chaining
Sourcepub const fn swap(&mut self, id: &mut Id<T>)
pub const fn swap(&mut self, id: &mut Id<T>)
swap
the inner value with that of another identifier instance of
the same type T
Sourcepub fn map<U, F>(self, f: F) -> Id<U>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> Id<U>where
F: FnOnce(T) -> U,
apply a function onto the inner value and return a new instance with the result
Sourcepub fn step(&mut self) -> T
pub fn step(&mut self) -> T
replaces the current id with the next logical value of type T
use scsys::Id;
let mut id = Id::zero();
assert_eq!(id.step(), 0);
assert_eq!(id.step(), 1);
Trait Implementations§
Source§impl<T> BorrowMut<T> for Id<T>
impl<T> BorrowMut<T> for Id<T>
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<'de, T> Deserialize<'de> for Id<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Id<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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: Ord> Ord for Id<T>
impl<T: Ord> Ord for Id<T>
Source§impl<Q> PartialOrd<Q> for Id<Q>where
Q: PartialOrd,
impl<Q> PartialOrd<Q> for Id<Q>where
Q: PartialOrd,
Source§impl<T: PartialOrd> PartialOrd for Id<T>
impl<T: PartialOrd> PartialOrd for Id<T>
impl<T: Copy> Copy for Id<T>
impl<T: Eq> Eq for Id<T>
impl<T> Identifier for Id<T>
impl<T> StructuralPartialEq for Id<T>
Auto Trait Implementations§
impl<T> Freeze for Id<T>where
T: Freeze,
impl<T> RefUnwindSafe for Id<T>where
T: RefUnwindSafe,
impl<T> Send for Id<T>where
T: Send,
impl<T> Sync for Id<T>where
T: Sync,
impl<T> Unpin for Id<T>where
T: Unpin,
impl<T> UnwindSafe for Id<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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S> Identify for Swhere
S: Identifier,
impl<S> Identify for Swhere
S: Identifier,
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>,
Return a random value via the
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>,
Generate a random value in the given range. Read more
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
Return a bool with a probability
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
Return a bool with a probability of
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>,
Sample a new value, using the given distribution. Read more
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,
Create an iterator that generates values using the given distribution. Read more
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
👎Deprecated since 0.9.0: Renamed to
random
to avoid conflict with the new gen
keyword in Rust 2024.Alias for
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>,
👎Deprecated since 0.9.0: Renamed to
random_range
Alias for
Rng::random_range
.Source§impl<R> TryRngCore for R
impl<R> TryRngCore for R
Source§type Error = Infallible
type Error = Infallible
The type returned in the event of a RNG error.
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>
Return the next random
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>
Return the next random
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>
Fill
dest
entirely with random data.Source§fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
fn unwrap_mut(&mut self) -> UnwrapMut<'_, Self>
Wrap RNG with the
UnwrapMut
wrapper.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self>where
Self: Sized,
Convert an
RngCore
to a RngReadAdapter
.