pub struct StateId<T: StateValue>(/* private fields */);
Expand description
Unique identifier of a value in a state map.
The type T
is the value type.
static_id! {
static ref FOO_ID: StateId<bool>;
}
let mut owned_state = OwnedStateMap::<()>::default();
let foo = owned_state.borrow_mut().set(*FOO_ID, true);
§Memory
The internal number is a NonZeroU64
, that means that
Option<StateId>
and
StateId
are the same size as u64
.
§As Hash
The generated internal number has good statistical distribution and can be used as its own hash,
although it is not cryptographically safe, as it is simply a sequential counter scrambled using splitmix64
.
§Static
The unique ID cannot be generated at compile time, but you can use the static_id!
macro to declare
a lazy static that instantiates the ID.
Implementations§
source§impl<T: StateValue> StateId<T>
impl<T: StateValue> StateId<T>
sourcepub fn new_unique() -> Self
pub fn new_unique() -> Self
Generates a new unique ID.
sourcepub fn sequential(self) -> u64
pub fn sequential(self) -> u64
Un-scramble the underlying value to get the original sequential count number.
If two IDs, id0
and id1
where generated by the same thread then id0.sequential() < id1.sequential()
.
sourcepub fn from_raw(raw: u64) -> Self
pub fn from_raw(raw: u64) -> Self
Creates an ID from a raw value.
The value must not be zero, panics if it is, the value must have been provided by get
otherwise
the ID will not be unique.
sourcepub fn from_sequential(num: u64) -> Self
pub fn from_sequential(num: u64) -> Self
Creates an ID from a sequential
number.
§Safety
The value must not be zero, panics if it is, the value must have been provided by sequential
otherwise
the ID will not be unique.
Trait Implementations§
source§impl<T: StateValue> Clone for StateId<T>
impl<T: StateValue> Clone for StateId<T>
source§impl<T: StateValue> Debug for StateId<T>
impl<T: StateValue> Debug for StateId<T>
source§impl<T: StateValue> Hash for StateId<T>
impl<T: StateValue> Hash for StateId<T>
source§impl<T: StateValue> PartialEq for StateId<T>
impl<T: StateValue> PartialEq for StateId<T>
source§impl<T: StateValue> UniqueId for StateId<T>
impl<T: StateValue> UniqueId for StateId<T>
source§fn new_unique() -> Self
fn new_unique() -> Self
impl<T: StateValue> Copy for StateId<T>
impl<T: StateValue> Eq for StateId<T>
impl<T: StateValue> NoUninit for StateId<T>
impl<T: StateValue> PodInOption for StateId<T>
impl<T: StateValue> ZeroableInOption for StateId<T>
Auto Trait Implementations§
impl<T> Freeze for StateId<T>
impl<T> RefUnwindSafe for StateId<T>where
T: RefUnwindSafe,
impl<T> Send for StateId<T>
impl<T> Sync for StateId<T>
impl<T> Unpin for StateId<T>where
T: Unpin,
impl<T> UnwindSafe for StateId<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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more