1use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
7pub struct SessionId {
8 pub id: u64,
9 pub external_id: Option<String>,
10}
11
12impl SessionId {
13 pub fn new(id: u64) -> Self {
14 Self {
15 id,
16 external_id: None,
17 }
18 }
19
20 pub fn with_external_id(id: u64, external_id: impl Into<String>) -> Self {
21 Self {
22 id,
23 external_id: Some(external_id.into()),
24 }
25 }
26}
27
28impl std::fmt::Display for SessionId {
29 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30 if let Some(ref ext) = self.external_id {
31 write!(f, "{}({})", self.id, ext)
32 } else {
33 write!(f, "{}", self.id)
34 }
35 }
36}