mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-25 22:20:31 +00:00
Chore: implement Clone & Copy
common traits (#350)
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: https://github.com/ratatui-org/ratatui/issues/307
This commit is contained in:
parent
6f659cfb07
commit
440f62ff54
11 changed files with 20 additions and 20 deletions
|
@ -42,7 +42,7 @@ use crate::{
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct CrosstermBackend<W: Write> {
|
pub struct CrosstermBackend<W: Write> {
|
||||||
buffer: W,
|
buffer: W,
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ impl From<Color> for CColor {
|
||||||
/// The `ModifierDiff` struct is used to calculate the difference between two `Modifier`
|
/// 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
|
/// values. This is useful when updating the terminal display, as it allows for more
|
||||||
/// efficient updates by only sending the necessary changes.
|
/// efficient updates by only sending the necessary changes.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
struct ModifierDiff {
|
struct ModifierDiff {
|
||||||
pub from: Modifier,
|
pub from: Modifier,
|
||||||
pub to: Modifier,
|
pub to: Modifier,
|
||||||
|
|
|
@ -31,7 +31,7 @@ use crate::{
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct TermionBackend<W>
|
pub struct TermionBackend<W>
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
|
@ -164,16 +164,16 @@ where
|
||||||
self.stdout.flush()
|
self.stdout.flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
struct Fg(Color);
|
struct Fg(Color);
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
struct Bg(Color);
|
struct Bg(Color);
|
||||||
|
|
||||||
/// The `ModifierDiff` struct is used to calculate the difference between two `Modifier`
|
/// 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
|
/// values. This is useful when updating the terminal display, as it allows for more
|
||||||
/// efficient updates by only sending the necessary changes.
|
/// efficient updates by only sending the necessary changes.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
struct ModifierDiff {
|
struct ModifierDiff {
|
||||||
from: Modifier,
|
from: Modifier,
|
||||||
to: Modifier,
|
to: Modifier,
|
||||||
|
|
|
@ -28,7 +28,7 @@ use crate::{
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TestBackend {
|
pub struct TestBackend {
|
||||||
width: u16,
|
width: u16,
|
||||||
buffer: Buffer,
|
buffer: Buffer,
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub enum Corner {
|
||||||
BottomLeft,
|
BottomLeft,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Hash, Clone, Eq, PartialEq)]
|
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
Horizontal,
|
Horizontal,
|
||||||
#[default]
|
#[default]
|
||||||
|
@ -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 struct Margin {
|
||||||
pub vertical: u16,
|
pub vertical: u16,
|
||||||
pub horizontal: u16,
|
pub horizontal: u16,
|
||||||
|
@ -368,7 +368,7 @@ fn split(area: Rect, layout: &Layout) -> Rc<[Rect]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A container used by the solver inside split
|
/// A container used by the solver inside split
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
struct Element {
|
struct Element {
|
||||||
x: Variable,
|
x: Variable,
|
||||||
y: Variable,
|
y: Variable,
|
||||||
|
|
|
@ -23,7 +23,7 @@ pub struct TerminalOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Interface to the terminal backed by Termion
|
/// Interface to the terminal backed by Termion
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct Terminal<B>
|
pub struct Terminal<B>
|
||||||
where
|
where
|
||||||
B: Backend,
|
B: Backend,
|
||||||
|
@ -139,7 +139,7 @@ where
|
||||||
/// `CompletedFrame` represents the state of the terminal after all changes performed in the last
|
/// `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`] call have been applied. Therefore, it is only valid until the next call to
|
||||||
/// [`Terminal::draw`].
|
/// [`Terminal::draw`].
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CompletedFrame<'a> {
|
pub struct CompletedFrame<'a> {
|
||||||
pub buffer: &'a Buffer,
|
pub buffer: &'a Buffer,
|
||||||
pub area: Rect,
|
pub area: Rect,
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
widgets::{Borders, Widget},
|
widgets::{Borders, Widget},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum BorderType {
|
pub enum BorderType {
|
||||||
#[default]
|
#[default]
|
||||||
Plain,
|
Plain,
|
||||||
|
@ -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 struct Padding {
|
||||||
pub left: u16,
|
pub left: u16,
|
||||||
pub right: u16,
|
pub right: u16,
|
||||||
|
|
|
@ -21,7 +21,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Display a month calendar for the month containing `display_date`
|
/// Display a month calendar for the month containing `display_date`
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Monthly<'a, S: DateStyler> {
|
pub struct Monthly<'a, S: DateStyler> {
|
||||||
display_date: Date,
|
display_date: Date,
|
||||||
events: S,
|
events: S,
|
||||||
|
@ -173,7 +173,7 @@ pub trait DateStyler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A simple `DateStyler` based on a [`HashMap`]
|
/// A simple `DateStyler` based on a [`HashMap`]
|
||||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct CalendarEventStore(pub HashMap<Date, Style>);
|
pub struct CalendarEventStore(pub HashMap<Date, Style>);
|
||||||
|
|
||||||
impl CalendarEventStore {
|
impl CalendarEventStore {
|
||||||
|
|
|
@ -355,7 +355,7 @@ impl<'a> Context<'a> {
|
||||||
/// });
|
/// });
|
||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Canvas<'a, F>
|
pub struct Canvas<'a, F>
|
||||||
where
|
where
|
||||||
F: Fn(&mut Context),
|
F: Fn(&mut Context),
|
||||||
|
|
|
@ -179,7 +179,7 @@ fn get_unicode_block<'a>(frac: f64) -> &'a str {
|
||||||
/// .line_set(symbols::line::THICK)
|
/// .line_set(symbols::line::THICK)
|
||||||
/// .ratio(0.4);
|
/// .ratio(0.4);
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct LineGauge<'a> {
|
pub struct LineGauge<'a> {
|
||||||
block: Option<Block<'a>>,
|
block: Option<Block<'a>>,
|
||||||
ratio: f64,
|
ratio: f64,
|
||||||
|
|
|
@ -208,7 +208,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A state machine that truncates overhanging lines.
|
/// A state machine that truncates overhanging lines.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct LineTruncator<'a, O, I>
|
pub struct LineTruncator<'a, O, I>
|
||||||
where
|
where
|
||||||
// Outer iterator providing the individual lines
|
// Outer iterator providing the individual lines
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An enum representing the direction of scrolling in a Scrollbar widget.
|
/// 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 {
|
pub enum ScrollDirection {
|
||||||
/// Forward scroll direction, usually corresponds to scrolling downwards or rightwards.
|
/// Forward scroll direction, usually corresponds to scrolling downwards or rightwards.
|
||||||
#[default]
|
#[default]
|
||||||
|
|
Loading…
Reference in a new issue