librojo/session_id.rs
1// Default doesn't make sense for a type whose constructor is random.
2#![allow(clippy::new_without_default)]
3
4use std::fmt;
5
6use serde::{Deserialize, Serialize};
7use uuid::Uuid;
8
9/// A randomly generated ID generated by Rojo during a serve session.
10///
11/// If the session ID of the server changes between requests, that indicates
12/// that a new server has started up and the session should be terminated.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
14pub struct SessionId(Uuid);
15
16impl SessionId {
17 pub fn new() -> SessionId {
18 SessionId(Uuid::new_v4())
19 }
20}
21
22impl fmt::Display for SessionId {
23 fn fmt(&self, writer: &mut fmt::Formatter<'_>) -> fmt::Result {
24 write!(writer, "{}", self.0)
25 }
26}