mirror of
https://github.com/mii443/izoli.git
synced 2025-08-22 16:05:40 +00:00
impl FromStr for CGroupLimitValue
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user