o_sfu_router/model/
ids.rs1use std::fmt::{self, Display, Formatter};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4pub struct RouterId(pub u64);
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
13pub struct ConnectionId(u64);
14
15impl ConnectionId {
16 #[must_use]
17 pub fn allocate(next_connection_id: &mut u64) -> Self {
18 let connection_id = Self(*next_connection_id);
19 *next_connection_id = next_connection_id.saturating_add(1);
20 connection_id
21 }
22
23 #[must_use]
24 pub const fn from_raw(raw: u64) -> Self {
25 Self(raw)
26 }
27
28 #[must_use]
29 pub const fn as_u64(self) -> u64 {
30 self.0
31 }
32}
33
34impl Display for ConnectionId {
35 fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
36 self.0.fmt(formatter)
37 }
38}
39
40#[repr(transparent)]
46#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
47pub struct MediaWorkerId(usize);
48
49impl MediaWorkerId {
50 #[must_use]
51 pub const fn from_raw(raw: usize) -> Self {
52 Self(raw)
53 }
54
55 #[must_use]
56 pub const fn as_usize(self) -> usize {
57 self.0
58 }
59}