use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum Capability {
Pure,
ReadFs,
WriteFs,
Net,
Process,
Device,
}
impl Capability {
pub const fn risk(self) -> u8 {
match self {
Self::Pure => 0,
Self::ReadFs => 1,
Self::WriteFs => 2,
Self::Net => 3,
Self::Process => 4,
Self::Device => 5,
}
}
}
impl Ord for Capability {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.risk().cmp(&other.risk())
}
}
impl PartialOrd for Capability {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl fmt::Display for Capability {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
Self::Pure => "pure",
Self::ReadFs => "read_fs",
Self::WriteFs => "write_fs",
Self::Net => "net",
Self::Process => "process",
Self::Device => "device",
};
f.write_str(s)
}
}