mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-29 08:00:38 +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(())
|
||||
/// # }
|
||||
/// ```
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct CrosstermBackend<W: Write> {
|
||||
buffer: W,
|
||||
}
|
||||
|
@ -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,
|
||||
|
|
|
@ -31,7 +31,7 @@ use crate::{
|
|||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct TermionBackend<W>
|
||||
where
|
||||
W: Write,
|
||||
|
@ -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,
|
||||
|
|
|
@ -28,7 +28,7 @@ use crate::{
|
|||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TestBackend {
|
||||
width: u16,
|
||||
buffer: Buffer,
|
||||
|
|
|
@ -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]
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
|
|
@ -355,7 +355,7 @@ impl<'a> Context<'a> {
|
|||
/// });
|
||||
/// });
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Canvas<'a, F>
|
||||
where
|
||||
F: Fn(&mut Context),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue