Skip to main content

srt/
socket_id.rs

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