From ab9fc3a8a014258f2f499ce48c71d6732b052cbe Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 19 Mar 2024 16:56:35 +0000 Subject: [PATCH] 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 --- test_infra/src/lib.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test_infra/src/lib.rs b/test_infra/src/lib.rs index ddf29eb29..09a1e6d45 100644 --- a/test_infra/src/lib.rs +++ b/test_infra/src/lib.rs @@ -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(()) } }