Skip to content

Commit

Permalink
chore: implement Eq & PartialEq common traits (#357)
Browse files Browse the repository at this point in the history
Reorder the derive fields to be more consistent:

    Debug, Default, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash

see: #307
  • Loading branch information
TieWay59 committed Aug 4, 2023
1 parent 554805d commit 181706c
Show file tree
Hide file tree
Showing 30 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/backend/crossterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use crate::{
/// # Ok(())
/// # }
/// ```
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct CrosstermBackend<W: Write> {
buffer: W,
}
Expand Down Expand Up @@ -213,7 +213,7 @@ impl From<Color> for CColor {
/// The `ModifierDiff` struct is used to calculate the difference between two `Modifier`
/// values. This is useful when updating the terminal display, as it allows for more
/// efficient updates by only sending the necessary changes.
#[derive(Debug, Default, Clone, Copy)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
struct ModifierDiff {
pub from: Modifier,
pub to: Modifier,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub use self::test::TestBackend;

/// Enum representing the different types of clearing operations that can be performed
/// on the terminal screen.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum ClearType {
All,
AfterCursor,
Expand Down
8 changes: 4 additions & 4 deletions src/backend/termion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
/// # Ok(())
/// # }
/// ```
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct TermionBackend<W>
where
W: Write,
Expand Down Expand Up @@ -164,16 +164,16 @@ where
self.stdout.flush()
}
}
#[derive(Debug, Default, Clone, Copy)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
struct Fg(Color);

#[derive(Debug, Default, Clone, Copy)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
struct Bg(Color);

/// The `ModifierDiff` struct is used to calculate the difference between two `Modifier`
/// values. This is useful when updating the terminal display, as it allows for more
/// efficient updates by only sending the necessary changes.
#[derive(Debug, Default, Clone, Copy)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
struct ModifierDiff {
from: Modifier,
to: Modifier,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
/// # Ok(())
/// # }
/// ```
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct TestBackend {
width: u16,
buffer: Buffer,
Expand Down
8 changes: 4 additions & 4 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use cassowary::{
WeightedRelation::{EQ, GE, LE},
};

#[derive(Debug, Default, Hash, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
pub enum Corner {
#[default]
TopLeft,
Expand Down Expand Up @@ -70,15 +70,15 @@ pub struct Margin {
pub horizontal: u16,
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
pub enum Alignment {
#[default]
Left,
Center,
Right,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct Layout {
direction: Direction,
margin: Margin,
Expand Down Expand Up @@ -368,7 +368,7 @@ fn split(area: Rect, layout: &Layout) -> Rc<[Rect]> {
}

/// A container used by the solver inside split
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
struct Element {
x: Variable,
y: Variable,
Expand Down
4 changes: 2 additions & 2 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bitflags! {
/// let m = Modifier::BOLD | Modifier::ITALIC;
/// ```
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Clone, Copy, PartialEq, Eq)]
#[derive(Default, Clone, Copy, Eq, PartialEq)]
pub struct Modifier: u16 {
const BOLD = 0b0000_0000_0001;
const DIM = 0b0000_0000_0010;
Expand Down Expand Up @@ -423,7 +423,7 @@ impl Style {
}

/// Error type indicating a failure to parse a color string.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct ParseColorError;

impl std::fmt::Display for ParseColorError {
Expand Down
10 changes: 5 additions & 5 deletions src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod block {
pub const ONE_QUARTER: &str = "▎";
pub const ONE_EIGHTH: &str = "▏";

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Set {
pub full: &'static str,
pub seven_eighths: &'static str,
Expand Down Expand Up @@ -62,7 +62,7 @@ pub mod bar {
pub const ONE_QUARTER: &str = "▂";
pub const ONE_EIGHTH: &str = "▁";

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Set {
pub full: &'static str,
pub seven_eighths: &'static str,
Expand Down Expand Up @@ -155,7 +155,7 @@ pub mod line {
pub const DOUBLE_CROSS: &str = "╬";
pub const THICK_CROSS: &str = "╋";

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Set {
pub vertical: &'static str,
pub horizontal: &'static str,
Expand Down Expand Up @@ -240,7 +240,7 @@ pub mod braille {
}

/// Marker to use when plotting data points
#[derive(Debug, Default, Clone, Copy)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
pub enum Marker {
/// One point per cell in shape of dot
#[default]
Expand All @@ -265,7 +265,7 @@ pub mod scrollbar {
/// │ └──────── thumb
/// └─────────── begin
/// ```
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct Set {
pub track: &'static str,
pub thumb: &'static str,
Expand Down
4 changes: 2 additions & 2 deletions src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct TerminalOptions {
}

/// Interface to the terminal backed by Termion
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct Terminal<B>
where
B: Backend,
Expand Down Expand Up @@ -139,7 +139,7 @@ where
/// `CompletedFrame` represents the state of the terminal after all changes performed in the last
/// [`Terminal::draw`] call have been applied. Therefore, it is only valid until the next call to
/// [`Terminal::draw`].
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CompletedFrame<'a> {
pub buffer: &'a Buffer,
pub area: Rect,
Expand Down
2 changes: 1 addition & 1 deletion src/text/grapheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::style::{Style, Styled};
/// it actually is not a member of the text type hierarchy (`Text` -> `Line` -> `Span`).
/// It is a separate type used mostly for rendering purposes. A `Span` consists of components that
/// can be split into `StyledGrapheme`s, but it does not contain a collection of `StyledGrapheme`s.
#[derive(Debug, Default, Clone, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct StyledGrapheme<'a> {
pub symbol: &'a str,
pub style: Style,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/barchart/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{buffer::Buffer, style::Style, text::Line};
/// .value_style(Style::default().bg(Color::Red).fg(Color::White))
/// .text_value("10°C".to_string());
/// ```
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct Bar<'a> {
/// Value to display on the bar (computed when the data is passed to the widget)
pub(super) value: u64,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/barchart/bar_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::text::Line;
/// .label("Group 1".into())
/// .bars(&[Bar::default().value(200), Bar::default().value(150)]);
/// ```
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct BarGroup<'a> {
/// label of the group. It will be printed centered under this group of bars
pub(super) label: Option<Line<'a>>,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/barchart/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use super::{Block, Widget};
/// .data(BarGroup::default().bars(&[Bar::default().value(10), Bar::default().value(20)]))
/// .max(4);
/// ```
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct BarChart<'a> {
/// Block to wrap the widget in
block: Option<Block<'a>>,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
widgets::{Borders, Widget},
};

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
pub enum BorderType {
#[default]
Plain,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
};

/// Display a month calendar for the month containing `display_date`
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Monthly<'a, S: DateStyler> {
display_date: Date,
events: S,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/canvas/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};

/// Shape to draw a circle with a given center and radius and with the given color
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Circle {
pub x: f64,
pub y: f64,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/canvas/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};

/// Shape to draw a line from (x1, y1) to (x2, y2) with the given color
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Line {
pub x1: f64,
pub y1: f64,
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/canvas/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
},
};

#[derive(Debug, Default, Clone, Copy)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
pub enum MapResolution {
#[default]
Low,
Expand All @@ -23,7 +23,7 @@ impl MapResolution {
}

/// Shape to draw a world map with the given resolution and color
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct Map {
pub resolution: MapResolution,
pub color: Color,
Expand Down
10 changes: 5 additions & 5 deletions src/widgets/canvas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ pub trait Shape {
}

/// Label to draw some text on the canvas
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Label<'a> {
x: f64,
y: f64,
line: TextLine<'a>,
}

#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
struct Layer {
string: String,
colors: Vec<Color>,
Expand All @@ -51,7 +51,7 @@ trait Grid: Debug {
fn reset(&mut self);
}

#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
struct BrailleGrid {
width: u16,
height: u16,
Expand Down Expand Up @@ -114,7 +114,7 @@ impl Grid for BrailleGrid {
}
}

#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
struct CharGrid {
width: u16,
height: u16,
Expand Down Expand Up @@ -355,7 +355,7 @@ impl<'a> Context<'a> {
/// });
/// });
/// ```
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Canvas<'a, F>
where
F: Fn(&mut Context),
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/canvas/points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};

/// A shape to draw a group of points with the given color
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Points<'a> {
pub coords: &'a [(f64, f64)],
pub color: Color,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/canvas/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};

/// Shape to draw a rectangle from a `Rect` with the given color
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Rectangle {
pub x: f64,
pub y: f64,
Expand Down
10 changes: 5 additions & 5 deletions src/widgets/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
};

/// An X or Y axis for the chart widget
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Axis<'a> {
/// Title displayed next to axis end
title: Option<TextLine<'a>>,
Expand Down Expand Up @@ -76,7 +76,7 @@ impl<'a> Axis<'a> {
}

/// Used to determine which style of graphing to use
#[derive(Debug, Default, Clone, Copy)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
pub enum GraphType {
/// Draw each point
#[default]
Expand All @@ -86,7 +86,7 @@ pub enum GraphType {
}

/// A group of data points
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Dataset<'a> {
/// Name of the dataset (used in the legend if shown)
name: Cow<'a, str>,
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<'a> Dataset<'a> {

/// A container that holds all the infos about where to display each elements of the chart (axis,
/// labels, legend, ...).
#[derive(Debug, Default, Clone, PartialEq)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
struct ChartLayout {
/// Location of the title of the x axis
title_x: Option<(u16, u16)>,
Expand Down Expand Up @@ -188,7 +188,7 @@ struct ChartLayout {
/// .bounds([0.0, 10.0])
/// .labels(["0.0", "5.0", "10.0"].iter().cloned().map(Span::from).collect()));
/// ```
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Chart<'a> {
/// A block to display around the widget eventually
block: Option<Block<'a>>,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{buffer::Buffer, layout::Rect, widgets::Widget};
///
/// For a more complete example how to utilize `Clear` to realize popups see
/// the example `examples/popup.rs`
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct Clear;

impl Widget for Clear {
Expand Down

0 comments on commit 181706c

Please sign in to comment.