Browse Source

Replace Default impls that use state with fns

The Default impls for DefaultFormat and LoadFormat were originally called ‘new’, to which Clippy suggested that they be changed. But as these functions change based on what the year is, a function called something other than ‘new’, like ‘load’.
Benjamin Sago 7 years ago
parent
commit
c2bb986618
2 changed files with 7 additions and 7 deletions
  1. 3 3
      src/options/view.rs
  2. 4 4
      src/output/time.rs

+ 3 - 3
src/options/view.rs

@@ -257,16 +257,16 @@ impl TimeFormat {
                 use options::vars;
                 use options::vars;
                 match vars.get(vars::TIME_STYLE) {
                 match vars.get(vars::TIME_STYLE) {
                     Some(ref t) if !t.is_empty() => t.clone(),
                     Some(ref t) if !t.is_empty() => t.clone(),
-                    _                            => return Ok(TimeFormat::DefaultFormat(DefaultFormat::default()))
+                    _                            => return Ok(TimeFormat::DefaultFormat(DefaultFormat::load()))
                 }
                 }
             },
             },
         };
         };
 
 
         if &word == "default" {
         if &word == "default" {
-            Ok(TimeFormat::DefaultFormat(DefaultFormat::default()))
+            Ok(TimeFormat::DefaultFormat(DefaultFormat::load()))
         }
         }
         else if &word == "iso" {
         else if &word == "iso" {
-            Ok(TimeFormat::ISOFormat(ISOFormat::default()))
+            Ok(TimeFormat::ISOFormat(ISOFormat::load()))
         }
         }
         else if &word == "long-iso" {
         else if &word == "long-iso" {
             Ok(TimeFormat::LongISO)
             Ok(TimeFormat::LongISO)

+ 4 - 4
src/output/time.rs

@@ -88,8 +88,8 @@ pub struct DefaultFormat {
     pub date_and_year: DateFormat<'static>,
     pub date_and_year: DateFormat<'static>,
 }
 }
 
 
-impl Default for DefaultFormat {
-    fn default() -> DefaultFormat {
+impl DefaultFormat {
+    pub fn load() -> DefaultFormat {
         use unicode_width::UnicodeWidthStr;
         use unicode_width::UnicodeWidthStr;
 
 
         let locale = locale::Time::load_user_locale()
         let locale = locale::Time::load_user_locale()
@@ -201,8 +201,8 @@ pub struct ISOFormat {
     pub current_year: i64,
     pub current_year: i64,
 }
 }
 
 
-impl Default for ISOFormat {
-    fn default() -> ISOFormat {
+impl ISOFormat {
+    pub fn load() -> ISOFormat {
         let current_year = LocalDateTime::now().year();
         let current_year = LocalDateTime::now().year();
         ISOFormat { current_year }
         ISOFormat { current_year }
     }
     }