add fmt::Display for CGroupLimitValue

This commit is contained in:
mii443
2024-10-17 08:35:54 +00:00
parent 9bcea10ce4
commit 19f4f29e9a
2 changed files with 17 additions and 4 deletions

View File

@ -1,4 +1,5 @@
use std::{ use std::{
fmt,
fs::{self, File}, fs::{self, File},
io::{Read, Write}, io::{Read, Write},
path::PathBuf, path::PathBuf,
@ -148,7 +149,7 @@ impl CGroup {
fn get_limit_value<T>(&self, name: &str) -> Result<CGroupLimitValue<T>, std::io::Error> fn get_limit_value<T>(&self, name: &str) -> Result<CGroupLimitValue<T>, std::io::Error>
where where
T: FromStr, T: FromStr + fmt::Display,
{ {
let value = self.read(name)?; let value = self.read(name)?;

View File

@ -1,9 +1,9 @@
use std::str::FromStr; use std::{fmt, str::FromStr};
#[derive(Debug)] #[derive(Debug)]
pub enum CGroupLimitValue<T> pub enum CGroupLimitValue<T>
where where
T: FromStr, T: FromStr + std::fmt::Display,
{ {
Max, Max,
Value(T), Value(T),
@ -14,7 +14,7 @@ pub struct ParseCGroupLimitValueError;
impl<T> FromStr for CGroupLimitValue<T> impl<T> FromStr for CGroupLimitValue<T>
where where
T: FromStr, T: FromStr + std::fmt::Display,
{ {
type Err = ParseCGroupLimitValueError; 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}"),
}
}
}