pub struct UserId(/* private fields */);Expand description
Type-safe wrapper for user identifiers.
Stored as Arc<str> so clone() is a cheap atomic refcount increment
rather than a heap allocation — critical for high-concurrency hot paths.
Implementations§
Source§impl UserId
impl UserId
Sourcepub const MAX_LENGTH: usize = 128
pub const MAX_LENGTH: usize = 128
Maximum user ID length accepted from external input.
Sourcepub fn new(id: impl Into<String>) -> UserId
pub fn new(id: impl Into<String>) -> UserId
Creates a new UserId from a string.
§Panics
Panics if the ID contains path traversal characters. Use try_new() for fallible creation.
Sourcepub fn anonymous() -> UserId
pub fn anonymous() -> UserId
New anonymous UserId — cached singleton, clone is a free atomic increment.
Sourcepub fn try_new(id: impl Into<String>) -> Result<UserId, UserIdValidationError>
pub fn try_new(id: impl Into<String>) -> Result<UserId, UserIdValidationError>
Creates a new UserId from a string, returning an error if validation fails.
§Security
Validates that the ID does not contain path traversal characters and only uses the canonical safe alphabet:
..(parent directory)/or\(directory separators)- Null bytes (
\0) - ASCII letters, digits,
_, and-
This prevents path traversal attacks when user IDs are used in storage paths.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes the wrapper and returns the inner String.
Sourcepub fn is_anonymous(&self) -> bool
pub fn is_anonymous(&self) -> bool
Is anonymous user?
Trait Implementations§
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>,
impl Eq 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,
Source§impl StorageKey for UserId
impl StorageKey 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> 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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<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<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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)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.