use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ResourceId(pub u32);
impl fmt::Display for ResourceId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "r{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Resource {
id: ResourceId,
name: String,
capacity: u32,
}
impl Resource {
pub fn new(id: ResourceId, name: impl Into<String>, capacity: u32) -> Self {
Self {
id,
name: name.into(),
capacity,
}
}
#[inline]
pub fn id(&self) -> ResourceId {
self.id
}
#[inline]
pub fn name(&self) -> &str {
&self.name
}
#[inline]
pub fn capacity(&self) -> u32 {
self.capacity
}
#[inline]
pub fn is_unary(&self) -> bool {
self.capacity == 1
}
}