pavex_session/id.rs
1#[derive(
2 Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize,
3)]
4#[serde(transparent)]
5/// The identifier for a session.
6///
7/// # Format stability
8///
9/// The session ID is guaranteed to be a valid UUID.
10/// The format of the UUID is not guaranteed to be stable across different versions of this library.
11///
12/// It is recommended to treat the session ID as an opaque value in your application.
13/// Knowing the format is primarily useful when implementing custom session storage backends, as
14/// it allows you to leverage optimizations in your data store that are specific to the UUID format
15/// (e.g. a dedicated data type, such as `UUID` in PostgreSQL).
16pub struct SessionId(uuid::Uuid);
17
18impl SessionId {
19 /// Generate a new random identifier using the random number generator
20 /// provided by the underlying operating system.
21 pub fn random() -> Self {
22 Self(uuid::Uuid::new_v4())
23 }
24
25 /// Returns the inner `uuid::Uuid` value.
26 pub fn inner(&self) -> uuid::Uuid {
27 self.0
28 }
29}