pub struct StableId<Kind: StableIdKind> { /* private fields */ }Expand description
A 16-byte stable identifier, parameterized by role tag.
Construct via StableId::new_v7 for fresh IDs or
StableId::from_bytes to rehydrate from canonical-encoded form.
Two StableId values with different role tags are distinct types and
cannot be compared or converted without an explicit crossing.
Implementations§
Source§impl<Kind: StableIdKind> StableId<Kind>
impl<Kind: StableIdKind> StableId<Kind>
Sourcepub fn new_v7() -> Self
pub fn new_v7() -> Self
Generate a fresh UUIDv7 stable ID.
Uses the uuid crate’s Uuid::now_v7(), which combines the current
Unix timestamp (48 bits, millisecond resolution) with 74 bits of
CSPRNG entropy. See RFC 9562.
Sourcepub const fn from_bytes_raw(bytes: [u8; 16]) -> Self
pub const fn from_bytes_raw(bytes: [u8; 16]) -> Self
Construct from an explicit 16-byte array. The bytes are not validated
beyond their length - any 128-bit value is accepted. Callers who
want UUID shape validation should use StableId::parse_uuid.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, IdError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, IdError>
Construct from a byte slice of length 16, validating the length.
§Errors
Returns IdError::StableIdLength if bytes.len() != 16.
Sourcepub fn parse_uuid(s: &str) -> Result<Self, IdError>
pub fn parse_uuid(s: &str) -> Result<Self, IdError>
Parse from a canonical UUID string (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
§Errors
Returns IdError::StableIdParse if s is not a valid UUID.
Sourcepub const fn from_random_bytes(bytes: [u8; 16]) -> Self
pub const fn from_random_bytes(bytes: [u8; 16]) -> Self
Construct from 16 random bytes without UUID structure. Useful when
the caller has already generated cryptographically random bytes and
does not need UUIDv7’s time ordering. The value will not validate
as a UUIDv7 but will still function as a stable ID in mnem.
Sourcepub const fn into_bytes(self) -> [u8; 16]
pub const fn into_bytes(self) -> [u8; 16]
Consume and return the underlying 16 bytes.
Sourcepub fn to_uuid_string(&self) -> String
pub fn to_uuid_string(&self) -> String
Render as a lowercase hyphenated UUID string.