impl FromStr for CGroupLimitValue

This commit is contained in:
mii443
2024-10-17 07:56:13 +00:00
parent 5fd1095e84
commit 49b12fd296

View File

@ -1,5 +1,32 @@
use std::str::FromStr;
#[derive(Debug)]
pub enum CGroupLimitValue<T> {
pub enum CGroupLimitValue<T>
where
T: FromStr,
{
Max,
Value(T),
}
#[derive(Debug, PartialEq, Eq)]
pub struct ParseCGroupLimitValueError;
impl<T> FromStr for CGroupLimitValue<T>
where
T: FromStr,
{
type Err = ParseCGroupLimitValueError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.trim() == "max" {
Ok(Self::Max)
} else {
if let Ok(value) = T::from_str(s) {
Ok(Self::Value(value))
} else {
Err(ParseCGroupLimitValueError)
}
}
}
}