From c08eb90f161f278c7d362d4215d814e9abbb3185 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 30 Sep 2024 14:00:21 -0700 Subject: [PATCH] Use unwrap_or_default() when getting default color and verbosity (#2397) --- src/color.rs | 5 +---- src/run.rs | 2 +- src/verbosity.rs | 30 ++++++++++++++---------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/color.rs b/src/color.rs index 3c2969b8cc..ccdf218546 100644 --- a/src/color.rs +++ b/src/color.rs @@ -32,10 +32,7 @@ impl Color { } pub(crate) fn auto() -> Self { - Self { - use_color: UseColor::Auto, - ..Self::default() - } + Self::default() } #[cfg(test)] diff --git a/src/run.rs b/src/run.rs index 49b2725d2d..a07b73bbc9 100644 --- a/src/run.rs +++ b/src/run.rs @@ -18,7 +18,7 @@ pub fn run(args: impl Iterator + Clone>) -> Result<() let (color, verbosity) = config .as_ref() .map(|config| (config.color, config.verbosity)) - .unwrap_or((Color::auto(), Verbosity::default())); + .unwrap_or_default(); let loader = Loader::new(); diff --git a/src/verbosity.rs b/src/verbosity.rs index 4fc8c0df9f..f3ba3e4585 100644 --- a/src/verbosity.rs +++ b/src/verbosity.rs @@ -1,6 +1,4 @@ -use Verbosity::*; - -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] pub(crate) enum Verbosity { Quiet, Taciturn, @@ -11,14 +9,14 @@ pub(crate) enum Verbosity { impl Verbosity { pub(crate) fn from_flag_occurrences(flag_occurrences: u8) -> Self { match flag_occurrences { - 0 => Taciturn, - 1 => Loquacious, - _ => Grandiloquent, + 0 => Self::Taciturn, + 1 => Self::Loquacious, + _ => Self::Grandiloquent, } } pub(crate) fn quiet(self) -> bool { - matches!(self, Quiet) + self == Self::Quiet } pub(crate) fn loud(self) -> bool { @@ -26,20 +24,20 @@ impl Verbosity { } pub(crate) fn loquacious(self) -> bool { - match self { - Quiet | Taciturn => false, - Loquacious | Grandiloquent => true, - } + self >= Self::Loquacious } pub(crate) fn grandiloquent(self) -> bool { - match self { - Quiet | Taciturn | Loquacious => false, - Grandiloquent => true, - } + self >= Self::Grandiloquent } pub const fn default() -> Self { - Taciturn + Self::Taciturn + } +} + +impl Default for Verbosity { + fn default() -> Self { + Self::default() } }