use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SessionId(Arc<str>);
impl SessionId {
#[must_use]
pub fn new(name: impl Into<Arc<str>>) -> Self {
Self(name.into())
}
#[must_use]
pub fn default_session() -> Self {
Self::new("default")
}
#[must_use]
pub fn name(&self) -> &str {
&self.0
}
}
impl Default for SessionId {
fn default() -> Self {
Self::default_session()
}
}
impl std::fmt::Display for SessionId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<&str> for SessionId {
fn from(s: &str) -> Self {
Self::new(s)
}
}
impl From<String> for SessionId {
fn from(s: String) -> Self {
Self::new(s)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ClientId(usize);
impl ClientId {
#[must_use]
pub const fn new(id: usize) -> Self {
Self(id)
}
#[must_use]
pub const fn as_usize(&self) -> usize {
self.0
}
}
impl std::fmt::Display for ClientId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "client-{}", self.0)
}
}
#[cfg(test)]
#[path = "id_tests.rs"]
mod tests;