Răsfoiți Sursa

refactor: use #[default] attribute instead of custom impl for enums

Terts Diepraam 2 ani în urmă
părinte
comite
c9527835ae
3 a modificat fișierele cu 8 adăugiri și 28 ștergeri
  1. 2 7
      src/fs/dir.rs
  2. 2 7
      src/output/file_name.rs
  3. 4 14
      src/output/table.rs

+ 2 - 7
src/fs/dir.rs

@@ -203,7 +203,7 @@ impl<'dir, 'ig> Iterator for Files<'dir, 'ig> {
 /// Usually files in Unix use a leading dot to be hidden or visible, but two
 /// entries in particular are “extra-hidden”: `.` and `..`, which only become
 /// visible after an extra `-a` option.
-#[derive(PartialEq, Eq, Debug, Copy, Clone)]
+#[derive(PartialEq, Eq, Debug, Default, Copy, Clone)]
 pub enum DotFilter {
     /// Shows files, dotfiles, and `.` and `..`.
     DotfilesAndDots,
@@ -212,15 +212,10 @@ pub enum DotFilter {
     Dotfiles,
 
     /// Just show files, hiding anything beginning with a dot.
+    #[default]
     JustFiles,
 }
 
-impl Default for DotFilter {
-    fn default() -> Self {
-        Self::JustFiles
-    }
-}
-
 impl DotFilter {
     /// Whether this filter should show dotfiles in a listing.
     fn shows_dotfiles(self) -> bool {

+ 2 - 7
src/output/file_name.rs

@@ -69,9 +69,10 @@ enum LinkStyle {
 }
 
 /// Whether to append file class characters to the file names.
-#[derive(PartialEq, Eq, Debug, Copy, Clone)]
+#[derive(PartialEq, Eq, Debug, Default, Copy, Clone)]
 pub enum Classify {
     /// Just display the file names, without any characters.
+    #[default]
     JustFilenames,
 
     /// Always add a character after the file name depending on what class of
@@ -82,12 +83,6 @@ pub enum Classify {
     AutomaticAddFileIndicators,
 }
 
-impl Default for Classify {
-    fn default() -> Self {
-        Self::JustFilenames
-    }
-}
-
 /// When displaying a directory name, there needs to be some way to handle
 /// mount details, depending on how long the resulting Cell can be.
 #[derive(PartialEq, Debug, Copy, Clone)]

+ 4 - 14
src/output/table.rs

@@ -230,10 +230,11 @@ impl Column {
 
 /// Formatting options for file sizes.
 #[allow(clippy::enum_variant_names)]
-#[derive(PartialEq, Eq, Debug, Copy, Clone)]
+#[derive(PartialEq, Eq, Debug, Default, Copy, Clone)]
 pub enum SizeFormat {
     /// Format the file size using **decimal** prefixes, such as “kilo”,
     /// “mega”, or “giga”.
+    #[default]
     DecimalBytes,
 
     /// Format the file size using **binary** prefixes, such as “kibi”,
@@ -262,12 +263,6 @@ pub enum GroupFormat {
     Smart,
 }
 
-impl Default for SizeFormat {
-    fn default() -> Self {
-        Self::DecimalBytes
-    }
-}
-
 /// The types of a file’s time fields. These three fields are standard
 /// across most (all?) operating systems.
 #[derive(PartialEq, Eq, Debug, Copy, Clone)]
@@ -308,20 +303,15 @@ impl TimeType {
 }
 
 /// How display file flags.
-#[derive(PartialEq, Eq, Debug, Copy, Clone)]
+#[derive(PartialEq, Eq, Debug, Default, Copy, Clone)]
 pub enum FlagsFormat {
     /// Display flags as comma seperated descriptions
+    #[default]
     Long,
     /// Display flags as single character abbreviations (Windows only)
     Short,
 }
 
-impl Default for FlagsFormat {
-    fn default() -> Self {
-        Self::Long
-    }
-}
-
 impl FlagsFormat {
     pub(crate) fn deduce<V: Vars>(vars: &V) -> FlagsFormat {
         vars.get(EZA_WINDOWS_ATTRIBUTES)