#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
#[derive(EnumCount, EnumIter)]
#[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub enum Controller
{
io,
memory,
pids,
perf_event,
rdma,
cpu,
cpuset,
hugetlb,
debug,
}
impl FromBytes for Controller
{
type Error = ParseControllerError;
#[inline(always)]
fn from_bytes(bytes: &[u8]) -> Result<Self, Self::Error>
{
use self::Controller::*;
let variant = match bytes
{
b"io" => io,
b"memory" => memory,
b"pids" => pids,
b"perf_event" => perf_event,
b"rdma" => rdma,
b"cpu" => cpu,
b"cpuset" => cpuset,
b"hugetlb" => hugetlb,
b"debug" => debug,
_ => return Err(ParseControllerError::UnknownVariant(bytes.to_vec()))
};
Ok(variant)
}
}
impl Controller
{
const MaximumNumberOfControllers: usize = Self::COUNT;
#[inline(always)]
pub fn is_domain_controller(self) -> bool
{
!self.is_threaded_controller()
}
#[inline(always)]
pub fn is_threaded_controller(self) -> bool
{
use self::Controller::*;
match self
{
io => false,
memory => false,
pids => true,
perf_event => true,
rdma => false,
cpu => true,
cpuset => true,
hugetlb => false,
debug => true,
}
}
#[inline(always)]
pub fn is_implicit_controller(self) -> bool
{
use self::Controller::*;
match self
{
io => false,
memory => false,
pids => false,
perf_event => true,
rdma => false,
cpu => false,
cpuset => false,
hugetlb => false,
debug => true,
}
}
#[inline(always)]
fn append_to(self, line: &mut Vec<u8>, sign: u8)
{
line.push(sign);
line.extend_from_slice(self.to_bytes())
}
#[inline(always)]
fn is_controller(value: &[u8]) -> bool
{
Self::from_bytes(value).is_ok()
}
#[inline(always)]
fn to_bytes(self) -> &'static [u8]
{
use self::Controller::*;
match self
{
io => b"io" as &[u8],
memory => b"memory" as &[u8],
pids => b"pids" as &[u8],
perf_event => b"perf_event" as &[u8],
rdma => b"rdma" as &[u8],
cpu => b"cpu" as &[u8],
cpuset => b"cpuset" as &[u8],
hugetlb => b"hugetlb" as &[u8],
debug => b"debug" as &[u8],
}
}
}