Add wrapper types for short IDs

This commit is contained in:
Lambda 2024-08-27 14:27:12 +00:00
parent f1642c92d1
commit b0f33207fe
28 changed files with 427 additions and 232 deletions

View file

@ -1,4 +1,27 @@
mod data;
macro_rules! short_id_type {
($name:ident) => {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub(crate) struct $name(u64);
impl $name {
pub(crate) fn new(id: u64) -> Self {
Self(id)
}
pub(crate) fn get(&self) -> u64 {
self.0
}
}
};
}
short_id_type!(ShortRoomId);
short_id_type!(ShortEventId);
short_id_type!(ShortStateHash);
short_id_type!(ShortStateKey);
pub(crate) use data::Data;
pub(crate) type Service = &'static dyn Data;