Explorar el Código

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 hace 7 años
padre
commit
c2bb986618
Se han modificado 2 ficheros con 7 adiciones y 7 borrados
  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;
                 match vars.get(vars::TIME_STYLE) {
                     Some(ref t) if !t.is_empty() => t.clone(),
-                    _                            => return Ok(TimeFormat::DefaultFormat(DefaultFormat::default()))
+                    _                            => return Ok(TimeFormat::DefaultFormat(DefaultFormat::load()))
                 }
             },
         };
 
         if &word == "default" {
-            Ok(TimeFormat::DefaultFormat(DefaultFormat::default()))
+            Ok(TimeFormat::DefaultFormat(DefaultFormat::load()))
         }
         else if &word == "iso" {
-            Ok(TimeFormat::ISOFormat(ISOFormat::default()))
+            Ok(TimeFormat::ISOFormat(ISOFormat::load()))
         }
         else if &word == "long-iso" {
             Ok(TimeFormat::LongISO)

+ 4 - 4
src/output/time.rs

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