use std::borrow::Cow;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum PermissionMode {
#[default]
All,
Any,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Permission {
name: Cow<'static, str>,
}
impl Permission {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: Cow::Owned(name.into()),
}
}
pub fn from_static(name: &'static str) -> Self {
Self {
name: Cow::Borrowed(name),
}
}
pub fn name(&self) -> &str {
&self.name
}
}
impl std::fmt::Display for Permission {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.name)
}
}
impl From<&'static str> for Permission {
fn from(value: &'static str) -> Self {
Self::from_static(value)
}
}
impl From<String> for Permission {
fn from(value: String) -> Self {
Self::new(value)
}
}