Use `Display` instead of custom `to_string`

Marshall Bowers created

Change summary

crates/ui2/src/prelude.rs | 46 ++++++++++++++++++++++++----------------
1 file changed, 28 insertions(+), 18 deletions(-)

Detailed changes

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]