Skip to content

Commit

Permalink
refactor: dont manually impl Default for defaults (ratatui#1142)
Browse files Browse the repository at this point in the history
Replace `impl Default` by `#[derive(Default)]` when its implementation
equals.
  • Loading branch information
EdJoPaTo authored and joshka committed Oct 14, 2024
1 parent 67477ba commit 424b692
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 42 deletions.
8 changes: 1 addition & 7 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Color>,
Expand All @@ -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;

Expand Down
15 changes: 1 addition & 14 deletions src/widgets/gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Block<'a>>,
ratio: f64,
Expand All @@ -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`].
///
Expand Down
8 changes: 1 addition & 7 deletions src/widgets/scrollbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
///
Expand Down
15 changes: 1 addition & 14 deletions src/widgets/sparkline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Block<'a>>,
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 424b692

Please sign in to comment.