Pārlūkot izejas kodu

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 gadi atpakaļ
vecāks
revīzija
c2bb986618
2 mainītis faili ar 7 papildinājumiem un 7 dzēšanām
  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 }
     }