From edcb74a7177580b7f2505a3057e6f7befcaaf170 Mon Sep 17 00:00:00 2001 From: Takeru Ohta Date: Sat, 11 Feb 2023 23:39:58 +0900 Subject: [PATCH] Fix clippy(nightly) warnings --- src/syslog/facility.rs | 9 ++------- src/syslog/format.rs | 9 ++------- src/terminal.rs | 8 ++------ src/types.rs | 42 ++++++++++++------------------------------ 4 files changed, 18 insertions(+), 50 deletions(-) diff --git a/src/syslog/facility.rs b/src/syslog/facility.rs index 54a6ff4..ce855f6 100644 --- a/src/syslog/facility.rs +++ b/src/syslog/facility.rs @@ -13,7 +13,7 @@ use std::str::FromStr; /// `enum` are available on all platforms, and variants not present on the /// target platform will be mapped to a reasonable alternative. #[allow(missing_docs)] -#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +#[derive(Default, Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] #[non_exhaustive] #[serde(rename_all = "lowercase")] pub enum Facility { @@ -110,6 +110,7 @@ pub enum Facility { Security, Syslog, + #[default] User, Uucp, } @@ -152,12 +153,6 @@ impl Facility { } } -impl Default for Facility { - fn default() -> Self { - Facility::User - } -} - impl Display for Facility { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str(self.name()) diff --git a/src/syslog/format.rs b/src/syslog/format.rs index 819b6b0..0c88587 100644 --- a/src/syslog/format.rs +++ b/src/syslog/format.rs @@ -350,23 +350,18 @@ fn test_default_msg_format() { } /// Enumeration of built-in `MsgFormat`s, for use with serde. -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Default, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] #[non_exhaustive] #[serde(rename_all = "snake_case")] pub enum MsgFormatConfig { /// [`DefaultMsgFormat`](struct.DefaultMsgFormat.html). + #[default] Default, /// [`BasicMsgFormat`](struct.BasicMsgFormat.html). Basic, } -impl Default for MsgFormatConfig { - fn default() -> Self { - MsgFormatConfig::Default - } -} - impl From for Arc { fn from(conf: MsgFormatConfig) -> Self { Self::from(&conf) diff --git a/src/terminal.rs b/src/terminal.rs index d0ef21a..c685fc7 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -132,20 +132,16 @@ impl Build for TerminalLoggerBuilder { /// /// assert_eq!(Destination::default(), Destination::Stderr); /// ``` -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum Destination { /// Standard output. Stdout, /// Standard error. + #[default] Stderr, } -impl Default for Destination { - fn default() -> Self { - Destination::Stderr - } -} impl Destination { fn to_decorator(self) -> Decorator { let maybe_term_decorator = match self { diff --git a/src/types.rs b/src/types.rs index 2ab2268..07936d0 100644 --- a/src/types.rs +++ b/src/types.rs @@ -28,11 +28,14 @@ use std::str::FromStr; /// /// See [slog's documentation](https://docs.rs/slog/2.2.3/slog/#notable-details) for more details. #[allow(missing_docs)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +#[derive( + Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, +)] #[serde(rename_all = "lowercase")] pub enum Severity { Trace, Debug, + #[default] Info, Warning, Error, @@ -56,11 +59,6 @@ impl Severity { LevelFilter::new(drain, self.as_level()) } } -impl Default for Severity { - fn default() -> Self { - Severity::Info - } -} impl FromStr for Severity { type Err = Error; fn from_str(s: &str) -> Result { @@ -159,11 +157,12 @@ impl KVFilterParameters { /// /// assert_eq!(Format::default(), Format::Full); /// ``` -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] #[non_exhaustive] pub enum Format { /// Full format. + #[default] Full, /// Compact format. @@ -173,11 +172,6 @@ pub enum Format { #[cfg(feature = "json")] Json, } -impl Default for Format { - fn default() -> Self { - Format::Full - } -} impl FromStr for Format { type Err = Error; fn from_str(s: &str) -> Result { @@ -203,17 +197,13 @@ impl FromStr for Format { /// assert_eq!(TimeZone::default(), TimeZone::Local); /// ``` #[allow(missing_docs)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum TimeZone { Utc, + #[default] Local, } -impl Default for TimeZone { - fn default() -> Self { - TimeZone::Local - } -} impl FromStr for TimeZone { type Err = Error; fn from_str(s: &str) -> Result { @@ -237,20 +227,16 @@ impl FromStr for TimeZone { /// assert_eq!(SourceLocation::default(), SourceLocation::ModuleAndLine); /// ``` #[allow(missing_docs)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] #[non_exhaustive] pub enum SourceLocation { None, + #[default] ModuleAndLine, FileAndLine, LocalFileAndLine, } -impl Default for SourceLocation { - fn default() -> Self { - SourceLocation::ModuleAndLine - } -} impl FromStr for SourceLocation { type Err = Error; fn from_str(s: &str) -> Result { @@ -280,19 +266,15 @@ impl FromStr for SourceLocation { /// assert_eq!(OverflowStrategy::default(), OverflowStrategy::DropAndReport); /// ``` #[allow(missing_docs)] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] #[non_exhaustive] pub enum OverflowStrategy { + #[default] DropAndReport, Drop, Block, } -impl Default for OverflowStrategy { - fn default() -> Self { - OverflowStrategy::DropAndReport - } -} impl FromStr for OverflowStrategy { type Err = Error; fn from_str(s: &str) -> Result {