use std::ops::Deref;
use uuid::Uuid;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RequestId(String);
impl RequestId {
pub fn new() -> Self {
Self(Uuid::now_v7().to_string())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl Default for RequestId {
fn default() -> Self {
Self::new()
}
}
impl std::hash::Hash for RequestId {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
}
impl Deref for RequestId {
type Target = str;
fn deref(&self) -> &Self::Target {
self.as_str()
}
}
impl std::fmt::Display for RequestId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl<T: AsRef<str>> From<T> for RequestId {
fn from(s: T) -> Self {
Self(s.as_ref().to_string())
}
}