pub struct DeviceId(/* private fields */);Expand description
Device identifier, sibling to UserId / TenantId.
axess-minted: cryptographic opacity is the security contract, so
prefer Self::new over Self::from_namespaced_str in
production paths.
Backed by uuid::Uuid (16 bytes, Copy). UUID v4
random when minted via Self::new; v5 namespaced when
adopted from a non-UUID source via
Self::from_namespaced_str; bytes stored verbatim
when restored from persistence via Self::from_bytes.
Wire format under serde is the hyphenated UUID string;
under rkyv it’s the 16-byte archive layout.
Implementations§
Source§impl DeviceId
impl DeviceId
Sourcepub fn new<R>(rng: &R) -> DeviceIdwhere
R: SecureRng,
pub fn new<R>(rng: &R) -> DeviceIdwhere
R: SecureRng,
Mint a fresh UUID v4 from the supplied
SecureRng. Sets version 4 +
RFC 4122 variant bits per spec; the remaining 122
bits come from rng.
Sourcepub fn try_new(value: impl AsRef<str>) -> Result<DeviceId, IdError>
pub fn try_new(value: impl AsRef<str>) -> Result<DeviceId, IdError>
Construct from a string (which must be a valid hyphenated Uuid). Returns IdError::Empty for empty input or IdError::NotAUuid if parsing fails.
Sourcepub const fn from_bytes(bytes: [u8; 16]) -> DeviceId
pub const fn from_bytes(bytes: [u8; 16]) -> DeviceId
Construct from raw bytes verbatim (version and variant bits are not adjusted). For round-tripping persisted ids whose bytes already encode a valid Uuid.
Sourcepub fn from_random_bytes(bytes: [u8; 16]) -> DeviceId
pub fn from_random_bytes(bytes: [u8; 16]) -> DeviceId
Construct a UUID v4-shaped id from 16 random bytes (sets version + variant bits per RFC 4122).
Prefer Self::new. This constructor is for the
niche case where 16 random bytes have already been
drawn (e.g. from a fixed test seed buffer or an
external CSPRNG that doesn’t expose
SecureRng). When you have a
SecureRng in scope (production code always does,
tests should), Self::new(&mut rng) is the DST-correct
path: the only random source is the injected RNG, so
tests that mint identity remain reproducible across
runs.
Sourcepub fn from_namespaced_str(namespace: Uuid, name: &str) -> DeviceId
pub fn from_namespaced_str(namespace: Uuid, name: &str) -> DeviceId
Map a non-UUID adopter identifier (slug, OAuth subject,
integer-stringified, …) to a stable id via UUID v5.
Same (namespace, name) always produces the same id, so
services agree without coordination.
Sourcepub const fn as_bytes(&self) -> &[u8; 16]
pub const fn as_bytes(&self) -> &[u8; 16]
Borrow the raw 16-byte body. Zero-cost handoff to byte-shaped APIs.
Trait Implementations§
Source§impl Archive for DeviceId
impl Archive for DeviceId
Source§const COPY_OPTIMIZATION: CopyOptimization<DeviceId>
const COPY_OPTIMIZATION: CopyOptimization<DeviceId>
serialize. Read moreSource§type Archived = ArchivedDeviceId
type Archived = ArchivedDeviceId
Source§type Resolver = DeviceIdResolver
type Resolver = DeviceIdResolver
Source§impl<'de> Deserialize<'de> for DeviceId
impl<'de> Deserialize<'de> for DeviceId
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<DeviceId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<DeviceId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<'q, DB> Encode<'q, DB> for DeviceId
Available on crate feature sqlx only.
impl<'q, DB> Encode<'q, DB> for DeviceId
sqlx only.Source§fn encode_by_ref(
&self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>
fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Send + Sync>>
Source§fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>where
Self: Sized,
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Send + Sync>>where
Self: Sized,
self into buf in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Source§impl Ord for DeviceId
impl Ord for DeviceId
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for DeviceId
impl PartialOrd for DeviceId
Source§impl Serialize for DeviceId
impl Serialize for DeviceId
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,
impl Copy for DeviceId
impl Eq for DeviceId
impl StructuralPartialEq for DeviceId
Auto Trait Implementations§
impl Freeze for DeviceId
impl RefUnwindSafe for DeviceId
impl Send for DeviceId
impl Sync for DeviceId
impl Unpin for DeviceId
impl UnsafeUnpin for DeviceId
impl UnwindSafe for DeviceId
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
Source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive, it may be
unsized. Read moreSource§fn archived_metadata(
&self,
) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T, S> SerializeUnsized<S> for T
impl<T, S> SerializeUnsized<S> for T
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.