use std::fmt;
use std::sync::Arc;
use crate::ResourceError;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Resource(Arc<str>);
impl Resource {
pub fn new(name: impl Into<Arc<str>>) -> Result<Self, ResourceError> {
let name = name.into();
if name.is_empty() {
return Err(ResourceError::EmptyName);
}
Ok(Self(name))
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for Resource {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.0)
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BudgetId(pub(crate) u64);
impl BudgetId {
#[must_use]
pub const fn get(self) -> u64 {
self.0
}
}
impl fmt::Display for BudgetId {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(formatter)
}
}