mirror of
https://github.com/mii443/izoli.git
synced 2025-08-22 16:05:40 +00:00
add fmt::Display for CGroupLimitValue
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
use std::{
|
||||
fmt,
|
||||
fs::{self, File},
|
||||
io::{Read, Write},
|
||||
path::PathBuf,
|
||||
@ -148,7 +149,7 @@ impl CGroup {
|
||||
|
||||
fn get_limit_value<T>(&self, name: &str) -> Result<CGroupLimitValue<T>, std::io::Error>
|
||||
where
|
||||
T: FromStr,
|
||||
T: FromStr + fmt::Display,
|
||||
{
|
||||
let value = self.read(name)?;
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
use std::str::FromStr;
|
||||
use std::{fmt, str::FromStr};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CGroupLimitValue<T>
|
||||
where
|
||||
T: FromStr,
|
||||
T: FromStr + std::fmt::Display,
|
||||
{
|
||||
Max,
|
||||
Value(T),
|
||||
@ -14,7 +14,7 @@ pub struct ParseCGroupLimitValueError;
|
||||
|
||||
impl<T> FromStr for CGroupLimitValue<T>
|
||||
where
|
||||
T: FromStr,
|
||||
T: FromStr + std::fmt::Display,
|
||||
{
|
||||
type Err = ParseCGroupLimitValueError;
|
||||
|
||||
@ -30,3 +30,15 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> fmt::Display for CGroupLimitValue<T>
|
||||
where
|
||||
T: FromStr + fmt::Display,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
CGroupLimitValue::Max => write!(f, "max"),
|
||||
CGroupLimitValue::Value(value) => write!(f, "{value}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user