power: Move GPUPerformanceLevel::to_string to Display::fmt

This commit is contained in:
Vicki Pfau 2024-05-22 18:57:16 -07:00
parent b2f612cd45
commit b7b09e6c17
2 changed files with 11 additions and 10 deletions

View file

@ -197,7 +197,7 @@ async fn main() -> Result<()> {
Commands::GetGPUPerformanceLevel => {
let level = proxy.gpu_performance_level().await?;
match GPUPerformanceLevel::try_from(level) {
Ok(l) => println!("GPU performance level: {}", l.to_string()),
Ok(l) => println!("GPU performance level: {}", l),
Err(_) => println!("Got unknown value {level} from backend"),
}
}

View file

@ -6,6 +6,7 @@
*/
use anyhow::{bail, ensure, Error, Result};
use std::fmt;
use std::path::PathBuf;
use std::str::FromStr;
use tokio::fs::{self, File};
@ -63,15 +64,15 @@ impl FromStr for GPUPerformanceLevel {
}
}
impl ToString for GPUPerformanceLevel {
fn to_string(&self) -> String {
String::from(match self {
GPUPerformanceLevel::Auto => "auto",
GPUPerformanceLevel::Low => "low",
GPUPerformanceLevel::High => "high",
GPUPerformanceLevel::Manual => "manual",
GPUPerformanceLevel::ProfilePeak => "peak_performance",
})
impl fmt::Display for GPUPerformanceLevel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
GPUPerformanceLevel::Auto => write!(f, "auto"),
GPUPerformanceLevel::Low => write!(f, "low"),
GPUPerformanceLevel::High => write!(f, "high"),
GPUPerformanceLevel::Manual => write!(f, "manual"),
GPUPerformanceLevel::ProfilePeak => write!(f, "peak_performance"),
}
}
}