Skip to content

Commit

Permalink
Chore: implement Clone & Copy common traits (#350)
Browse files Browse the repository at this point in the history
Implement `Clone & Copy` common traits for most structs in src.

Only implement `Copy` for structs that are simple and trivial to copy.

Reorder the derive fields to be more consistent:

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

see: #307
  • Loading branch information
TieWay59 committed Jul 28, 2023
1 parent 6f659cf commit 440f62f
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 20 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)]
#[derive(Debug, Default, Clone)]
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)]
#[derive(Debug, Default, Clone, Copy)]
struct ModifierDiff {
pub from: Modifier,
pub to: Modifier,
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)]
#[derive(Debug, Default, Clone)]
pub struct TermionBackend<W>
where
W: Write,
Expand Down Expand Up @@ -164,16 +164,16 @@ where
self.stdout.flush()
}
}
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, Copy)]
struct Fg(Color);

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone, Copy)]
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)]
#[derive(Debug, Default, Clone, Copy)]
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)]
#[derive(Debug, Clone)]
pub struct TestBackend {
width: u16,
buffer: Buffer,
Expand Down
6 changes: 3 additions & 3 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum Corner {
BottomLeft,
}

#[derive(Debug, Default, Hash, Clone, Eq, PartialEq)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
pub enum Direction {
Horizontal,
#[default]
Expand Down Expand Up @@ -64,7 +64,7 @@ impl Constraint {
}
}

#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
pub struct Margin {
pub vertical: u16,
pub horizontal: u16,
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)]
#[derive(Debug, Clone, Copy)]
struct Element {
x: Variable,
y: Variable,
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)]
#[derive(Debug, Default, Clone)]
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)]
#[derive(Debug, Clone)]
pub struct CompletedFrame<'a> {
pub buffer: &'a Buffer,
pub area: Rect,
Expand Down
4 changes: 2 additions & 2 deletions 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, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum BorderType {
#[default]
Plain,
Expand All @@ -30,7 +30,7 @@ impl BorderType {
}
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Padding {
pub left: u16,
pub right: u16,
Expand Down
4 changes: 2 additions & 2 deletions 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)]
#[derive(Debug, Clone)]
pub struct Monthly<'a, S: DateStyler> {
display_date: Date,
events: S,
Expand Down Expand Up @@ -173,7 +173,7 @@ pub trait DateStyler {
}

/// A simple `DateStyler` based on a [`HashMap`]
#[derive(Clone, Eq, PartialEq, Debug)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct CalendarEventStore(pub HashMap<Date, Style>);

impl CalendarEventStore {
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/canvas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl<'a> Context<'a> {
/// });
/// });
/// ```
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Canvas<'a, F>
where
F: Fn(&mut Context),
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn get_unicode_block<'a>(frac: f64) -> &'a str {
/// .line_set(symbols::line::THICK)
/// .ratio(0.4);
/// ```
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct LineGauge<'a> {
block: Option<Block<'a>>,
ratio: f64,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/reflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ where
}

/// A state machine that truncates overhanging lines.
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct LineTruncator<'a, O, I>
where
// Outer iterator providing the individual lines
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/scrollbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
};

/// An enum representing the direction of scrolling in a Scrollbar widget.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
pub enum ScrollDirection {
/// Forward scroll direction, usually corresponds to scrolling downwards or rightwards.
#[default]
Expand Down

0 comments on commit 440f62f

Please sign in to comment.