Skip to main content

SessionId

Struct SessionId 

Source
pub struct SessionId(/* private fields */);
Expand description

Session identifier. axess-minted; cryptographic opacity is the security contract. A session-id leak that revealed login time would be a vulnerability for forensic correlation against externally-observed events, so prefer Self::new (UUID v4 random) over time-prefixed variants.

§Logging discipline

SessionId derives std::fmt::Debug and std::fmt::Display via define_id!; both formats produce the full hyphenated UUID string. Treat session ids as credentials in logs: a SessionId that lands in a structured-log line, an observability pipeline, or a crash dump leaks a still-valid authenticator. Redact at the emission boundary (a project-local RedactedSessionId(SessionId) newtype, or manual masking of middle bytes). axess-identity does not redact at the type level because the full id form is needed at the storage and authn-validation boundaries.

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 SessionId

Source

pub const NIL: SessionId

All-zero sentinel. Equal to Uuid::nil.

Source

pub fn new<R>(rng: &R) -> SessionId
where 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.

Source

pub fn try_new(value: impl AsRef<str>) -> Result<SessionId, IdError>

Construct from a string (which must be a valid hyphenated Uuid). Returns IdError::Empty for empty input or IdError::NotAUuid if parsing fails.

Source

pub const fn from_uuid(uuid: Uuid) -> SessionId

Wrap an existing Uuid.

Source

pub const fn from_bytes(bytes: [u8; 16]) -> SessionId

Construct from raw bytes verbatim (version and variant bits are not adjusted). For round-tripping persisted ids whose bytes already encode a valid Uuid.

Source

pub fn from_random_bytes(bytes: [u8; 16]) -> SessionId

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.

Source

pub fn from_namespaced_str(namespace: Uuid, name: &str) -> SessionId

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.

Source

pub const fn as_bytes(&self) -> &[u8; 16]

Borrow the raw 16-byte body. Zero-cost handoff to byte-shaped APIs.

Source

pub const fn as_uuid(&self) -> Uuid

Get the underlying Uuid. Zero-cost conversion to any sibling newtype (other_crate::FooId::from_uuid(id.as_uuid())).

Source

pub fn is_nil(&self) -> bool

true when this is the all-zero (Uuid::nil) sentinel.

Trait Implementations§

Source§

impl Archive for SessionId
where Uuid: Archive,

Source§

const COPY_OPTIMIZATION: CopyOptimization<SessionId>

An optimization flag that allows the bytes of this type to be copied directly to a writer instead of calling serialize. Read more
Source§

type Archived = ArchivedSessionId

The archived representation of this type. Read more
Source§

type Resolver = SessionIdResolver

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
Source§

fn resolve( &self, resolver: <SessionId as Archive>::Resolver, out: Place<<SessionId as Archive>::Archived>, )

Creates the archived version of this value at the given position and writes it to the given output. Read more
Source§

impl Clone for SessionId

Source§

fn clone(&self) -> SessionId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SessionId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'r, DB> Decode<'r, DB> for SessionId
where DB: Database, String: Decode<'r, DB>,

Available on crate feature sqlx only.
Source§

fn decode( value: <DB as Database>::ValueRef<'r>, ) -> Result<SessionId, Box<dyn Error + Send + Sync>>

Decode a new value of this type using a raw value from the database.
Source§

impl<'de> Deserialize<'de> for SessionId

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<SessionId, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<__D> Deserialize<SessionId, __D> for <SessionId as Archive>::Archived
where __D: Fallible + ?Sized, Uuid: Archive, <Uuid as Archive>::Archived: Deserialize<Uuid, __D>,

Source§

fn deserialize( &self, deserializer: &mut __D, ) -> Result<SessionId, <__D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl Display for SessionId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'q, DB> Encode<'q, DB> for SessionId
where DB: Database, String: Encode<'q, DB>,

Available on crate feature sqlx only.
Source§

fn encode_by_ref( &self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Send + Sync>>

Writes the value of self into buf without moving self. Read more
Source§

fn encode( self, buf: &mut <DB as Database>::ArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Send + Sync>>
where Self: Sized,

Writes the value of self into buf in the expected format for the database.
Source§

fn produces(&self) -> Option<<DB as Database>::TypeInfo>

Source§

fn size_hint(&self) -> usize

Source§

impl From<[u8; 16]> for SessionId

Source§

fn from(bytes: [u8; 16]) -> SessionId

Converts to this type from the input type.
Source§

impl From<Uuid> for SessionId

Source§

fn from(uuid: Uuid) -> SessionId

Converts to this type from the input type.
Source§

impl FromStr for SessionId

Source§

type Err = IdError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<SessionId, <SessionId as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for SessionId

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for SessionId

Source§

fn cmp(&self, other: &SessionId) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for SessionId

Source§

fn eq(&self, other: &SessionId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for SessionId

Source§

fn partial_cmp(&self, other: &SessionId) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<__S> Serialize<__S> for SessionId
where __S: Fallible + ?Sized, Uuid: Serialize<__S>,

Source§

fn serialize( &self, serializer: &mut __S, ) -> Result<<SessionId as Archive>::Resolver, <__S as Fallible>::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.
Source§

impl Serialize for SessionId

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Store<SessionId, SessionData> for MysqlSessionStore

Available on crate feature mysql only.
Source§

type Error = SqlStoreError

Backend-specific error. Use the shared StoreError enum for new backends; legacy wrappers may continue to surface SqlStoreError / ValkeyStoreError / PostgresStoreError until each is consolidated.
Source§

fn get( &self, key: &SessionId, ) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send

Fetch the value for key. Ok(None) when the key is absent (including TTL-expired); Err only on backend failure.
Source§

fn put( &self, key: &SessionId, value: &SessionData, ttl: Duration, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Insert or replace the value at key with the given TTL.
Source§

fn delete( &self, key: &SessionId, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Remove the entry at key. Idempotent; does not error if absent.
Source§

fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send

Bulk-evict every TTL-expired entry. Returns the number reclaimed. Backends with native TTL eviction (Valkey/Redis) may implement this as a no-op returning Ok(0); backends owning their own row table (SQLite, Postgres, in-memory) actually delete.
Source§

impl Store<SessionId, SessionData> for PostgresSessionStore

Available on crate feature postgres only.
Source§

type Error = SqlStoreError

Backend-specific error. Use the shared StoreError enum for new backends; legacy wrappers may continue to surface SqlStoreError / ValkeyStoreError / PostgresStoreError until each is consolidated.
Source§

fn get( &self, key: &SessionId, ) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send

Fetch the value for key. Ok(None) when the key is absent (including TTL-expired); Err only on backend failure.
Source§

fn put( &self, key: &SessionId, value: &SessionData, ttl: Duration, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Insert or replace the value at key with the given TTL.
Source§

fn delete( &self, key: &SessionId, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Remove the entry at key. Idempotent; does not error if absent.
Source§

fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send

Bulk-evict every TTL-expired entry. Returns the number reclaimed. Backends with native TTL eviction (Valkey/Redis) may implement this as a no-op returning Ok(0); backends owning their own row table (SQLite, Postgres, in-memory) actually delete.
Source§

impl Store<SessionId, SessionData> for SqliteSessionStore

Available on crate feature sqlite only.
Source§

type Error = SqlStoreError

Backend-specific error. Use the shared StoreError enum for new backends; legacy wrappers may continue to surface SqlStoreError / ValkeyStoreError / PostgresStoreError until each is consolidated.
Source§

fn get( &self, key: &SessionId, ) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send

Fetch the value for key. Ok(None) when the key is absent (including TTL-expired); Err only on backend failure.
Source§

fn put( &self, key: &SessionId, value: &SessionData, ttl: Duration, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Insert or replace the value at key with the given TTL.
Source§

fn delete( &self, key: &SessionId, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Remove the entry at key. Idempotent; does not error if absent.
Source§

fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send

Bulk-evict every TTL-expired entry. Returns the number reclaimed. Backends with native TTL eviction (Valkey/Redis) may implement this as a no-op returning Ok(0); backends owning their own row table (SQLite, Postgres, in-memory) actually delete.
Source§

impl Store<SessionId, SessionData> for ValkeySessionStore

Available on crate feature valkey only.
Source§

type Error = ValkeyStoreError

Backend-specific error. Use the shared StoreError enum for new backends; legacy wrappers may continue to surface SqlStoreError / ValkeyStoreError / PostgresStoreError until each is consolidated.
Source§

fn get( &self, key: &SessionId, ) -> impl Future<Output = Result<Option<SessionData>, Self::Error>> + Send

Fetch the value for key. Ok(None) when the key is absent (including TTL-expired); Err only on backend failure.
Source§

fn put( &self, key: &SessionId, value: &SessionData, ttl: Duration, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Insert or replace the value at key with the given TTL.
Source§

fn delete( &self, key: &SessionId, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Remove the entry at key. Idempotent; does not error if absent.
Source§

fn prune_expired(&self) -> impl Future<Output = Result<u64, Self::Error>> + Send

Bulk-evict every TTL-expired entry. Returns the number reclaimed. Backends with native TTL eviction (Valkey/Redis) may implement this as a no-op returning Ok(0); backends owning their own row table (SQLite, Postgres, in-memory) actually delete.
Source§

impl<DB> Type<DB> for SessionId
where DB: Database, String: Type<DB>,

Available on crate feature sqlx only.
Source§

fn type_info() -> <DB as Database>::TypeInfo

Returns the canonical SQL type for this Rust type. Read more
Source§

fn compatible(ty: &<DB as Database>::TypeInfo) -> bool

Determines if this Rust type is compatible with the given SQL type. Read more
Source§

impl Copy for SessionId

Source§

impl Eq for SessionId

Source§

impl StructuralPartialEq for SessionId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> ArchiveUnsized for T
where T: Archive,

Source§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
Source§

fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata

Creates the archived version of the metadata for this value.
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Fallible + Writer + ?Sized,

Source§

fn serialize_unsized( &self, serializer: &mut S, ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,