diff options
author | Benjamin Sago <ogham@bsago.me> | 2020-10-10 15:30:19 +0100 |
---|---|---|
committer | Benjamin Sago <ogham@bsago.me> | 2020-10-10 15:30:19 +0100 |
commit | f0c139ca682178e5cf4e735c0d7621719e73f6a0 (patch) | |
tree | 466fe7270a5dc7360f494a0e5c8c9b24d576c0cf /src/output/time.rs | |
parent | 70a30ed683ecc88304c6b2d66b6d34d61a1dd072 (diff) |
Better referencing
This commit makes changes to the way variables are referenced:
• Make types Copy when possible
• Make methods take `self` instead of `&self` where possible (trivially_copy_pass_by_ref)
• Remove unnecessary borrowing (needless_ref)
• Remove unnecessary cloning (clone_on_copy)
• Remove `ref` from match arms where possible (new Rust match ergonomics)
Diffstat (limited to 'src/output/time.rs')
-rw-r--r-- | src/output/time.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/output/time.rs b/src/output/time.rs index 551b548..521512c 100644 --- a/src/output/time.rs +++ b/src/output/time.rs @@ -51,20 +51,20 @@ pub enum TimeFormat { impl TimeFormat { pub fn format_local(&self, time: SystemTime) -> String { - match *self { - Self::DefaultFormat(ref fmt) => fmt.format_local(time), - Self::ISOFormat(ref iso) => iso.format_local(time), - Self::LongISO => long_local(time), - Self::FullISO => full_local(time), + match self { + Self::DefaultFormat(fmt) => fmt.format_local(time), + Self::ISOFormat(iso) => iso.format_local(time), + Self::LongISO => long_local(time), + Self::FullISO => full_local(time), } } pub fn format_zoned(&self, time: SystemTime, zone: &TimeZone) -> String { - match *self { - Self::DefaultFormat(ref fmt) => fmt.format_zoned(time, zone), - Self::ISOFormat(ref iso) => iso.format_zoned(time, zone), - Self::LongISO => long_zoned(time, zone), - Self::FullISO => full_zoned(time, zone), + match self { + Self::DefaultFormat(fmt) => fmt.format_zoned(time, zone), + Self::ISOFormat(iso) => iso.format_zoned(time, zone), + Self::LongISO => long_zoned(time, zone), + Self::FullISO => full_zoned(time, zone), } } } @@ -241,7 +241,7 @@ fn full_zoned(time: SystemTime, zone: &TimeZone) -> String { -#[derive(Debug, Clone)] +#[derive(Debug, Copy, Clone)] pub struct ISOFormat { /// The year of the current time. This gets used to determine which date @@ -257,12 +257,12 @@ impl ISOFormat { } impl ISOFormat { - fn is_recent(&self, date: LocalDateTime) -> bool { + fn is_recent(self, date: LocalDateTime) -> bool { date.year() == self.current_year } #[allow(trivial_numeric_casts)] - fn format_local(&self, time: SystemTime) -> String { + fn format_local(self, time: SystemTime) -> String { let date = LocalDateTime::at(systemtime_epoch(time)); if self.is_recent(date) { @@ -277,7 +277,7 @@ impl ISOFormat { } #[allow(trivial_numeric_casts)] - fn format_zoned(&self, time: SystemTime, zone: &TimeZone) -> String { + fn format_zoned(self, time: SystemTime, zone: &TimeZone) -> String { let date = zone.to_zoned(LocalDateTime::at(systemtime_epoch(time))); if self.is_recent(date) { |