srt_protocol/packet/
socket_id.rs

1use rand::distributions::{Distribution, Standard};
2use rand::Rng;
3
4use std::fmt;
5
6/// A newtype wrapper for strongly-typed SocketIDs
7#[derive(Copy, Clone, Eq, PartialEq, Hash)]
8pub struct SocketId(pub u32);
9
10impl Distribution<SocketId> for Standard {
11    fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> SocketId {
12        SocketId(rng.sample(self))
13    }
14}
15
16impl fmt::Debug for SocketId {
17    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
18        write!(f, "SRT#{:08X}", self.0)
19    }
20}