pub struct SessionId(/* private fields */);Expand description
Session identifier value object for type-safe session management
This value object provides type-safe session identification with session lifecycle management, security context tracking, and comprehensive validation capabilities. It implements Domain-Driven Design (DDD) value object patterns with immutable semantics and session-specific features.
§Key Features
- Type Safety: Strongly-typed session identifiers that cannot be confused with other IDs
- Session Lifecycle: ULID-based time-ordered creation sequence for session tracking
- Security Context: Natural chronological ordering for audit trails and security tracking
- Cross-Platform: Consistent representation across languages and storage systems
- Session Validation: Comprehensive session-specific validation with expiration management
- Serialization: Full serialization support for storage and API integration
§Benefits Over Raw ULIDs
- Type Safety:
SessionIdcannot be confused withPipelineIdor other entity IDs - Domain Semantics: Clear intent in function signatures and session business logic
- Session Validation: Session-specific validation rules with expiration and constraints
- Future Evolution: Extensible for session-specific methods and features
§Session Management Benefits
- Audit Trails: Natural time ordering for session events and security tracking
- Uniqueness: ULID guarantees global uniqueness across distributed systems
- Traceability: Easy tracking of session lifecycles and state changes
- Type Safety: Cannot be confused with other ID types in complex session workflows
- Expiration: Built-in expiration validation with configurable timeout periods
§Usage Examples
§Cross-Language Mapping
- Rust:
SessionIdnewtype wrapper with full validation - Go:
SessionIDstruct with equivalent interface - JSON: String representation of ULID for API compatibility
- Database: TEXT column with ULID string storage
Implementations§
Source§impl SessionId
impl SessionId
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new session ID with current timestamp
§Purpose
Generates a unique, time-ordered session identifier using ULID. Each session ID captures the exact moment of session creation.
§Why
Time-ordered session IDs provide:
- Natural chronological sorting for session tracking
- Built-in creation timestamp for expiration checks
- Guaranteed uniqueness across distributed systems
- Audit trail support without additional timestamps
§Returns
New SessionId with current millisecond timestamp
§Examples
Sourcepub fn from_ulid(ulid: Ulid) -> Result<Self, PipelineError>
pub fn from_ulid(ulid: Ulid) -> Result<Self, PipelineError>
Creates a session ID from an existing ULID
Sourcepub fn from_string(s: &str) -> Result<Self, PipelineError>
pub fn from_string(s: &str) -> Result<Self, PipelineError>
Creates a session ID from a string representation
Sourcepub fn from_timestamp_ms(timestamp_ms: u64) -> Self
pub fn from_timestamp_ms(timestamp_ms: u64) -> Self
Creates a session ID from a timestamp (for testing/migration)
Sourcepub fn timestamp_ms(&self) -> u64
pub fn timestamp_ms(&self) -> u64
Gets the timestamp component
Sourcepub fn validate(&self) -> Result<(), PipelineError>
pub fn validate(&self) -> Result<(), PipelineError>
Validates the session ID using category-specific rules
Sourcepub fn is_expired(&self, timeout_minutes: u64) -> bool
pub fn is_expired(&self, timeout_minutes: u64) -> bool
Checks if the session is expired based on timeout
Sourcepub fn age_minutes(&self) -> i64
pub fn age_minutes(&self) -> i64
Gets the session age in minutes
Trait Implementations§
Source§impl<'de> Deserialize<'de> for SessionId
impl<'de> Deserialize<'de> for SessionId
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Ord for SessionId
impl Ord for SessionId
Source§impl PartialOrd for SessionId
impl PartialOrd for SessionId
impl Eq for SessionId
impl StructuralPartialEq for SessionId
Auto Trait Implementations§
impl Freeze for SessionId
impl RefUnwindSafe for SessionId
impl Send for SessionId
impl Sync for SessionId
impl Unpin for SessionId
impl UnwindSafe for SessionId
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,
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 more