From 266101d2a64f8135ce1d80f675f4eb84b9010ec3 Mon Sep 17 00:00:00 2001 From: Joaquim Monteiro Date: Tue, 3 Dec 2024 09:47:39 +0000 Subject: [PATCH] refactor: implement Display for Status instead of ToString --- src/cargo_ops/elaborate_workspace.rs | 8 ++++---- src/cargo_ops/pkg_status.rs | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/cargo_ops/elaborate_workspace.rs b/src/cargo_ops/elaborate_workspace.rs index 352755f..9144fbd 100644 --- a/src/cargo_ops/elaborate_workspace.rs +++ b/src/cargo_ops/elaborate_workspace.rs @@ -317,8 +317,8 @@ impl<'ela> ElaborateWorkspace<'ela> { "{}\t{}\t{}\t{}\t{:?}\t{}\n", label, pkg.version(), - status.compat.to_string(), - status.latest.to_string(), + status.compat, + status.latest, dependency.kind(), dependency .platform() @@ -331,8 +331,8 @@ impl<'ela> ElaborateWorkspace<'ela> { "{}\t{}\t{}\t{}\t---\t---\n", name, pkg.version(), - status.compat.to_string(), - status.latest.to_string() + status.compat, + status.latest ); lines.insert(line); } diff --git a/src/cargo_ops/pkg_status.rs b/src/cargo_ops/pkg_status.rs index 0156bfb..7c1e501 100644 --- a/src/cargo_ops/pkg_status.rs +++ b/src/cargo_ops/pkg_status.rs @@ -1,3 +1,5 @@ +use std::fmt; + use semver::Version; /// Enum which represents the update status of a package @@ -24,12 +26,12 @@ impl Status { pub fn is_changed(&self) -> bool { !matches!(*self, Status::Unchanged) } } -impl ::std::string::ToString for Status { - fn to_string(&self) -> String { - match *self { - Status::Unchanged => "---".to_owned(), - Status::Removed => "Removed".to_owned(), - Status::Version(ref v) => v.to_string(), +impl fmt::Display for Status { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Status::Unchanged => write!(f, "---"), + Status::Removed => write!(f, "Removed"), + Status::Version(version) => version.fmt(f), } } }