test_infra: Implement fmt::Display for VerbosityLevel

warning: direct implementation of `ToString`
    --> test_infra/src/lib.rs:1214:1
     |
1214 | / impl ToString for VerbosityLevel {
1215 | |     fn to_string(&self) -> String {
1216 | |         use VerbosityLevel::*;
1217 | |         match self {
...    |
1222 | |     }
1223 | | }
     | |_^
     |
     = help: prefer implementing `Display` instead
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#to_string_trait_impl
     = note: `#[warn(clippy::to_string_trait_impl)]` on by default

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
This commit is contained in:
Rob Bradford 2024-03-19 16:56:35 +00:00 committed by Bo Chen
parent 1e3d21e504
commit ab9fc3a8a0

View File

@ -10,6 +10,7 @@ use serde_json::Value;
use ssh2::Session;
use std::env;
use std::ffi::OsStr;
use std::fmt::Display;
use std::io;
use std::io::{Read, Write};
use std::net::TcpListener;
@ -1211,14 +1212,15 @@ impl Default for VerbosityLevel {
}
}
impl ToString for VerbosityLevel {
fn to_string(&self) -> String {
impl Display for VerbosityLevel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use VerbosityLevel::*;
match self {
Warn => "".to_string(),
Info => "-v".to_string(),
Debug => "-vv".to_string(),
Warn => (),
Info => write!(f, "-v")?,
Debug => write!(f, "-vv")?,
}
Ok(())
}
}