30 lines
695 B
Rust
30 lines
695 B
Rust
use std::fmt::{Display, Formatter};
|
|
|
|
macro_rules! id_type {
|
|
($name:ident) => {
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, serde::Serialize)]
|
|
pub struct $name(pub i64);
|
|
|
|
impl From<i64> for $name {
|
|
fn from(value: i64) -> Self {
|
|
Self(value)
|
|
}
|
|
}
|
|
|
|
impl From<$name> for i64 {
|
|
fn from(value: $name) -> Self {
|
|
value.0
|
|
}
|
|
}
|
|
|
|
impl Display for $name {
|
|
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
|
|
self.0.fmt(formatter)
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
id_type!(UserId);
|
|
id_type!(IotaId);
|
|
id_type!(OmikronId);
|