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 => { Commands::GetGPUPerformanceLevel => {
let level = proxy.gpu_performance_level().await?; let level = proxy.gpu_performance_level().await?;
match GPUPerformanceLevel::try_from(level) { 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"), Err(_) => println!("Got unknown value {level} from backend"),
} }
} }

View file

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