Skip to main content

soma_mcp_client/upstream/relay/
session.rs

1use std::sync::atomic::{AtomicU64, Ordering};
2use std::sync::Arc;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5pub struct RelaySessionId(u64);
6
7impl RelaySessionId {
8    #[must_use]
9    pub fn get(self) -> u64 {
10        self.0
11    }
12}
13
14#[derive(Debug, Clone)]
15pub struct RelaySessionMint {
16    next: Arc<AtomicU64>,
17}
18
19impl Default for RelaySessionMint {
20    fn default() -> Self {
21        Self::new()
22    }
23}
24
25impl RelaySessionMint {
26    #[must_use]
27    pub fn new() -> Self {
28        Self {
29            next: Arc::new(AtomicU64::new(1)),
30        }
31    }
32
33    #[must_use]
34    pub fn mint(&self) -> RelaySessionId {
35        RelaySessionId(self.next.fetch_add(1, Ordering::Relaxed))
36    }
37}
38
39#[cfg(test)]
40#[path = "session_tests.rs"]
41mod tests;