pub struct TrustedRangeToken<T: IntegerId> { /* private fields */ }Expand description
Indicates that an IntegerId unsafely guarantees that the result of IntegerId::to_int
will always fall in the range IntegerId::MIN_INT..=IntegerId::MAX_ID.
Also guarantees that the IntegerId::to_int is implemented in the expected manner.
Just because the type implements something like bytemuck::Contiguous does not mean
that it is valid to create the token, as IntegerId::to_int could still be implemented incorrectly.
Implementations§
Source§impl<T: IntegerId> TrustedRangeToken<T>
impl<T: IntegerId> TrustedRangeToken<T>
Sourcepub const unsafe fn assume_valid() -> Self
pub const unsafe fn assume_valid() -> Self
Sourcepub const unsafe fn assume_valid_if<U: IntegerId>() -> Option<Self>
pub const unsafe fn assume_valid_if<U: IntegerId>() -> Option<Self>
Promise that the type T satisfies the appropriate correctness whenever U promises to.
This function is helpful for implementing newtype wrappers around an arbitrary inner type.
This is equivalent to T::TRUSTED_RANGE::map(|| unsafe { TrustedRangeToken::assume_valid() }),
but works in a const context.
§Safety
You must ensure that U can be trusted with the requirements of TrustedRangeToken
whenever U meets those same requirements.
Trait Implementations§
Source§impl<T: Clone + IntegerId> Clone for TrustedRangeToken<T>
impl<T: Clone + IntegerId> Clone for TrustedRangeToken<T>
Source§fn clone(&self) -> TrustedRangeToken<T>
fn clone(&self) -> TrustedRangeToken<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more