pub struct UserId(/* private fields */);Expand description
User (subject / principal) identifier. Adopter-supplied, same
constructor surface as TenantId. Distinct Self::SYSTEM
sentinel from the tenant so applications installing real rows
for both don’t collapse them.
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 UserId
impl UserId
Sourcepub fn new<R>(rng: &R) -> UserIdwhere
R: SecureRng,
pub fn new<R>(rng: &R) -> UserIdwhere
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<UserId, IdError>
pub fn try_new(value: impl AsRef<str>) -> Result<UserId, 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]) -> UserId
pub const fn from_bytes(bytes: [u8; 16]) -> UserId
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]) -> UserId
pub fn from_random_bytes(bytes: [u8; 16]) -> UserId
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) -> UserId
pub fn from_namespaced_str(namespace: Uuid, name: &str) -> UserId
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.
Source§impl UserId
impl UserId
Sourcepub const SYSTEM_STR: &'static str = "00000000-0000-0000-0000-000000000001"
pub const SYSTEM_STR: &'static str = "00000000-0000-0000-0000-000000000001"
String form of the reserved system-user identifier
("00000000-0000-0000-0000-000000000001"). Distinct from
TenantId::SYSTEM_STR so that an application installing
real rows for both doesn’t collapse the system tenant and
the system user onto the same identifier.
Sourcepub const SYSTEM: UserId
pub const SYSTEM: UserId
The reserved system-user sentinel: non-nil, distinct from
TenantId::SYSTEM.
Trait Implementations§
Source§impl Archive for UserId
impl Archive for UserId
Source§const COPY_OPTIMIZATION: CopyOptimization<UserId>
const COPY_OPTIMIZATION: CopyOptimization<UserId>
serialize. Read moreSource§type Archived = ArchivedUserId
type Archived = ArchivedUserId
Source§type Resolver = UserIdResolver
type Resolver = UserIdResolver
Source§impl<'de> Deserialize<'de> for UserId
impl<'de> Deserialize<'de> for UserId
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<UserId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<UserId, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<'q, DB> Encode<'q, DB> for UserId
Available on crate feature sqlx only.
impl<'q, DB> Encode<'q, DB> for UserId
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 UserId
impl Ord for UserId
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 UserId
impl PartialOrd for UserId
Source§impl Serialize for UserId
impl Serialize for UserId
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 UserId
impl Eq for UserId
impl StructuralPartialEq for UserId
Auto Trait Implementations§
impl Freeze for UserId
impl RefUnwindSafe for UserId
impl Send for UserId
impl Sync for UserId
impl Unpin for UserId
impl UnsafeUnpin for UserId
impl UnwindSafe for UserId
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.