websoc_kit/
connection_id.rsuse std::fmt;
use uuid::Uuid;
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct ConnectionId(Uuid);
impl Default for ConnectionId {
fn default() -> Self {
Self::new()
}
}
impl ConnectionId {
#[must_use]
pub fn new() -> Self {
ConnectionId(Uuid::new_v4())
}
#[must_use]
pub fn as_bytes(&self) -> &[u8; 16] {
self.0.as_bytes()
}
}
impl From<Uuid> for ConnectionId {
fn from(uuid: Uuid) -> Self {
ConnectionId(uuid)
}
}
impl From<ConnectionId> for Uuid {
fn from(connection_id: ConnectionId) -> Self {
connection_id.0
}
}
impl fmt::Debug for ConnectionId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ConnectionId({})", self.0)
}
}
impl fmt::Display for ConnectionId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0.simple())
}
}