From 9c10152c89c3052a4367b0a360461db86674ea56 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 26 Oct 2023 09:30:21 +0200 Subject: [PATCH] Use `Display` instead of custom `to_string` --- crates/ui2/src/prelude.rs | 46 ++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/crates/ui2/src/prelude.rs b/crates/ui2/src/prelude.rs index 2be30ff05a..141c20c505 100644 --- a/crates/ui2/src/prelude.rs +++ b/crates/ui2/src/prelude.rs @@ -26,13 +26,17 @@ pub enum FileSystemStatus { Deleted, } -impl FileSystemStatus { - pub fn to_string(&self) -> String { - match self { - Self::None => "None".to_string(), - Self::Conflict => "Conflict".to_string(), - Self::Deleted => "Deleted".to_string(), - } +impl std::fmt::Display for FileSystemStatus { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + Self::None => "None", + Self::Conflict => "Conflict", + Self::Deleted => "Deleted", + } + ) } } @@ -48,17 +52,6 @@ pub enum GitStatus { } impl GitStatus { - pub fn to_string(&self) -> String { - match self { - Self::None => "None".to_string(), - Self::Created => "Created".to_string(), - Self::Modified => "Modified".to_string(), - Self::Deleted => "Deleted".to_string(), - Self::Conflict => "Conflict".to_string(), - Self::Renamed => "Renamed".to_string(), - } - } - pub fn hsla(&self, cx: &WindowContext) -> Hsla { let theme = theme(cx); @@ -73,6 +66,23 @@ impl GitStatus { } } +impl std::fmt::Display for GitStatus { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + Self::None => "None", + Self::Created => "Created", + Self::Modified => "Modified", + Self::Deleted => "Deleted", + Self::Conflict => "Conflict", + Self::Renamed => "Renamed", + } + ) + } +} + #[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)] pub enum DiagnosticStatus { #[default]