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’.
This commit is contained in:
Benjamin Sago 2018-10-13 22:15:10 +01:00
parent 118426309d
commit c2bb986618
2 changed files with 7 additions and 7 deletions

View File

@ -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)

View File

@ -88,8 +88,8 @@ pub struct DefaultFormat {
pub date_and_year: DateFormat<'static>, pub date_and_year: DateFormat<'static>,
} }
impl Default for DefaultFormat { impl DefaultFormat {
fn default() -> 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 { impl ISOFormat {
fn default() -> ISOFormat { pub fn load() -> ISOFormat {
let current_year = LocalDateTime::now().year(); let current_year = LocalDateTime::now().year();
ISOFormat { current_year } ISOFormat { current_year }
} }