diff --git a/src/cgroup/limit_value.rs b/src/cgroup/limit_value.rs index 6ed402f..d114247 100644 --- a/src/cgroup/limit_value.rs +++ b/src/cgroup/limit_value.rs @@ -1,5 +1,32 @@ +use std::str::FromStr; + #[derive(Debug)] -pub enum CGroupLimitValue { +pub enum CGroupLimitValue +where + T: FromStr, +{ Max, Value(T), } + +#[derive(Debug, PartialEq, Eq)] +pub struct ParseCGroupLimitValueError; + +impl FromStr for CGroupLimitValue +where + T: FromStr, +{ + type Err = ParseCGroupLimitValueError; + + fn from_str(s: &str) -> Result { + if s.trim() == "max" { + Ok(Self::Max) + } else { + if let Ok(value) = T::from_str(s) { + Ok(Self::Value(value)) + } else { + Err(ParseCGroupLimitValueError) + } + } + } +}