1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
use rand::distributions::Standard; use rand::prelude::*; use std::fmt; #[derive(Debug, Clone, Copy)] pub struct TraceId(u64); impl TraceId { pub fn new() -> Self { random() } pub fn with_id(id: u64) -> Self { Self(id) } } impl Distribution<TraceId> for Standard { fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> TraceId { TraceId(rng.gen()) } } impl fmt::Display for TraceId { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) } }