From d92997105bde15a1fd43829466ec8cc46bffe121 Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Sat, 25 May 2024 19:34:48 +0200 Subject: [PATCH] refactor: dont manually impl Default for defaults (#1142) Replace `impl Default` by `#[derive(Default)]` when its implementation equals. --- src/style.rs | 8 +------- src/widgets/gauge.rs | 15 +-------------- src/widgets/scrollbar.rs | 8 +------- src/widgets/sparkline.rs | 15 +-------------- 4 files changed, 4 insertions(+), 42 deletions(-) diff --git a/src/style.rs b/src/style.rs index f208041d..6a29b034 100644 --- a/src/style.rs +++ b/src/style.rs @@ -222,7 +222,7 @@ impl fmt::Debug for Modifier { /// buffer.get(0, 0).style(), /// ); /// ``` -#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] +#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Style { pub fg: Option, @@ -233,12 +233,6 @@ pub struct Style { pub sub_modifier: Modifier, } -impl Default for Style { - fn default() -> Self { - Self::new() - } -} - impl Styled for Style { type Item = Self; diff --git a/src/widgets/gauge.rs b/src/widgets/gauge.rs index bc11b7e7..bc62f4dd 100644 --- a/src/widgets/gauge.rs +++ b/src/widgets/gauge.rs @@ -33,7 +33,7 @@ use crate::{prelude::*, widgets::Block}; /// /// - [`LineGauge`] for a thin progress bar #[allow(clippy::struct_field_names)] // gauge_style needs to be differentiated to style -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Default, Clone, PartialEq)] pub struct Gauge<'a> { block: Option>, ratio: f64, @@ -43,19 +43,6 @@ pub struct Gauge<'a> { gauge_style: Style, } -impl<'a> Default for Gauge<'a> { - fn default() -> Self { - Self { - block: None, - ratio: 0.0, - label: None, - use_unicode: false, - style: Style::default(), - gauge_style: Style::default(), - } - } -} - impl<'a> Gauge<'a> { /// Surrounds the `Gauge` with a [`Block`]. /// diff --git a/src/widgets/scrollbar.rs b/src/widgets/scrollbar.rs index 189bac6e..cec37a27 100644 --- a/src/widgets/scrollbar.rs +++ b/src/widgets/scrollbar.rs @@ -132,7 +132,7 @@ pub enum ScrollbarOrientation { /// /// If you don't have multi-line content, you can leave the `viewport_content_length` set to the /// default and it'll use the track size as a `viewport_content_length`. -#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] +#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ScrollbarState { /// The total length of the scrollable content. @@ -391,12 +391,6 @@ impl<'a> Scrollbar<'a> { } } -impl Default for ScrollbarState { - fn default() -> Self { - Self::new(0) - } -} - impl ScrollbarState { /// Constructs a new [`ScrollbarState`] with the specified content length. /// diff --git a/src/widgets/sparkline.rs b/src/widgets/sparkline.rs index ce12db1a..1eca9c5e 100644 --- a/src/widgets/sparkline.rs +++ b/src/widgets/sparkline.rs @@ -30,7 +30,7 @@ use crate::{prelude::*, widgets::Block}; /// .direction(RenderDirection::RightToLeft) /// .style(Style::default().red().on_white()); /// ``` -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Default, Clone, Eq, PartialEq)] pub struct Sparkline<'a> { /// A block to wrap the widget in block: Option>, @@ -59,19 +59,6 @@ pub enum RenderDirection { RightToLeft, } -impl<'a> Default for Sparkline<'a> { - fn default() -> Self { - Self { - block: None, - style: Style::default(), - data: &[], - max: None, - bar_set: symbols::bar::NINE_LEVELS, - direction: RenderDirection::LeftToRight, - } - } -} - impl<'a> Sparkline<'a> { /// Wraps the sparkline with the given `block`. #[must_use = "method moves the value of self and returns the modified value"]