#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ResourceOwnerId(u64);
impl ResourceOwnerId {
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ResourceSlotId(u64);
impl ResourceSlotId {
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ResourceGeneration(u64);
impl ResourceGeneration {
pub const INITIAL: Self = Self(0);
pub const MAX: Self = Self(u64::MAX);
pub const fn new(value: u64) -> Self {
Self(value)
}
pub const fn get(self) -> u64 {
self.0
}
pub const fn checked_next(self) -> Option<Self> {
match self.0.checked_add(1) {
Some(value) => Some(Self(value)),
None => None,
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ResourceToken {
owner: ResourceOwnerId,
slot: ResourceSlotId,
generation: ResourceGeneration,
}
impl ResourceToken {
pub const fn new(
owner: ResourceOwnerId,
slot: ResourceSlotId,
generation: ResourceGeneration,
) -> Self {
Self {
owner,
slot,
generation,
}
}
pub const fn owner(self) -> ResourceOwnerId {
self.owner
}
pub const fn slot(self) -> ResourceSlotId {
self.slot
}
pub const fn generation(self) -> ResourceGeneration {
self.generation
}
}