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)
}
}