1
0
Fork 0
forked from wry/wry

autocommit 2022-01-06 19:08:32 CET

This commit is contained in:
Julian Orth 2022-01-06 19:08:32 +01:00
parent cbbc41a463
commit 4a939477a2
51 changed files with 3438 additions and 207 deletions

View file

@ -92,3 +92,71 @@ macro_rules! id {
}
};
}
macro_rules! linear_ids {
($ids:ident, $id:ident) => {
pub struct $ids {
next: crate::utils::numcell::NumCell<u32>,
}
impl Default for $ids {
fn default() -> Self {
Self {
next: crate::utils::numcell::NumCell::new(1),
}
}
}
impl $ids {
pub fn next(&self) -> $id {
$id(self.next.fetch_add(1))
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct $id(u32);
impl $id {
pub fn raw(&self) -> u32 {
self.0
}
}
impl std::fmt::Display for $id {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}
};
}
macro_rules! cenum {
($name:ident, $uc:ident; $($name2:ident = $val:expr,)*) => {
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct $name(pub(super) u32);
impl $name {
pub fn raw(self) -> u32 {
self.0
}
}
pub const $uc: &[u32] = &[$($val,)*];
$(
pub const $name2: $name = $name($val);
)*
}
}
macro_rules! bitor {
($name:ident) => {
impl std::ops::BitOr for $name {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
}
};
}