From d31d0d0d764bb3126787553cf175afb7d0bf9d21 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 13 Jul 2020 12:54:03 -0700 Subject: [PATCH] Derive more stuff --- cursive-core/src/align.rs | 6 +++--- cursive-core/src/direction.rs | 8 ++++---- cursive-core/src/rect.rs | 2 +- cursive-core/src/theme/effect.rs | 2 +- cursive-core/src/theme/style.rs | 2 +- cursive-core/src/utils/lines/simple/row.rs | 2 +- cursive-core/src/utils/lines/spans/chunk.rs | 4 ++-- cursive-core/src/utils/lines/spans/row.rs | 2 +- cursive-core/src/utils/lines/spans/segment.rs | 2 +- cursive-core/src/utils/span.rs | 10 +++++----- cursive-core/src/view/margins.rs | 2 +- cursive-core/src/view/position.rs | 2 +- cursive-core/src/view/size_constraint.rs | 2 +- cursive-core/src/views/dialog.rs | 2 +- cursive-core/src/views/stack_view.rs | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cursive-core/src/align.rs b/cursive-core/src/align.rs index a34eb9a..8d9bba9 100644 --- a/cursive-core/src/align.rs +++ b/cursive-core/src/align.rs @@ -1,7 +1,7 @@ //! Tools to control view alignment. /// Specifies the alignment along both horizontal and vertical directions. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Align { /// Horizontal alignment policy pub h: HAlign, @@ -62,7 +62,7 @@ impl Align { } /// Horizontal alignment -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum HAlign { /// Place the element to the left of available space Left, @@ -73,7 +73,7 @@ pub enum HAlign { } /// Vertical alignment -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum VAlign { /// Place the element at the top of available space Top, diff --git a/cursive-core/src/direction.rs b/cursive-core/src/direction.rs index d5c1e03..9091ad3 100644 --- a/cursive-core/src/direction.rs +++ b/cursive-core/src/direction.rs @@ -30,7 +30,7 @@ use crate::Vec2; use crate::XY; /// Describes a vertical or horizontal orientation for a view. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Orientation { /// Horizontal orientation Horizontal, @@ -126,7 +126,7 @@ impl Orientation { /// /// * Absolute directions are Up, Down, Left, and Right. /// * Relative directions are Front and Back. -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Direction { /// An absolute direction. Abs(Absolute), @@ -199,7 +199,7 @@ impl Direction { } /// Direction relative to an orientation. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Relative { // TODO: handle right-to-left? (Arabic, ...) /// Front relative direction. @@ -261,7 +261,7 @@ impl Relative { } /// Absolute direction (up, down, left, right). -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Absolute { /// Left Left, diff --git a/cursive-core/src/rect.rs b/cursive-core/src/rect.rs index b310d3d..fc1afaf 100644 --- a/cursive-core/src/rect.rs +++ b/cursive-core/src/rect.rs @@ -5,7 +5,7 @@ use crate::Vec2; use std::ops::Add; /// A non-empty rectangle on the 2D grid. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Rect { /// Top-left corner, inclusive top_left: Vec2, diff --git a/cursive-core/src/theme/effect.rs b/cursive-core/src/theme/effect.rs index 1f72593..a2160f9 100644 --- a/cursive-core/src/theme/effect.rs +++ b/cursive-core/src/theme/effect.rs @@ -1,7 +1,7 @@ use enumset::EnumSetType; /// Text effect -#[derive(EnumSetType, Debug)] +#[derive(EnumSetType, Debug, Hash)] pub enum Effect { /// No effect Simple, diff --git a/cursive-core/src/theme/style.rs b/cursive-core/src/theme/style.rs index aaf22cf..93230fd 100644 --- a/cursive-core/src/theme/style.rs +++ b/cursive-core/src/theme/style.rs @@ -4,7 +4,7 @@ use enumset::{enum_set, EnumSet}; /// Combine a color and an effect. /// /// Represents any transformation that can be applied to text. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct Style { /// Effect to apply. /// diff --git a/cursive-core/src/utils/lines/simple/row.rs b/cursive-core/src/utils/lines/simple/row.rs index 594dcfa..c338aac 100644 --- a/cursive-core/src/utils/lines/simple/row.rs +++ b/cursive-core/src/utils/lines/simple/row.rs @@ -4,7 +4,7 @@ use crate::With; /// /// A row is made of offsets into a parent `String`. /// The corresponding substring should take `width` cells when printed. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Row { /// Beginning of the row in the parent `String`. pub start: usize, diff --git a/cursive-core/src/utils/lines/spans/chunk.rs b/cursive-core/src/utils/lines/spans/chunk.rs index bd87783..620f8be 100644 --- a/cursive-core/src/utils/lines/spans/chunk.rs +++ b/cursive-core/src/utils/lines/spans/chunk.rs @@ -3,7 +3,7 @@ use super::segment::Segment; /// Non-splittable piece of text. /// /// It is made of a list of segments of text. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Chunk { /// Total width of this chunk. pub width: usize, @@ -81,7 +81,7 @@ impl Chunk { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)] /// Describes a part of a chunk. /// /// Includes both length and width to ease some computations. diff --git a/cursive-core/src/utils/lines/spans/row.rs b/cursive-core/src/utils/lines/spans/row.rs index 5e2f740..5f7f575 100644 --- a/cursive-core/src/utils/lines/spans/row.rs +++ b/cursive-core/src/utils/lines/spans/row.rs @@ -2,7 +2,7 @@ use super::Segment; use crate::utils::span::{IndexedCow, Span, SpannedStr}; /// A list of segments representing a row of text -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Row { /// List of segments pub segments: Vec, diff --git a/cursive-core/src/utils/lines/spans/segment.rs b/cursive-core/src/utils/lines/spans/segment.rs index 917f8a9..ec5db27 100644 --- a/cursive-core/src/utils/lines/spans/segment.rs +++ b/cursive-core/src/utils/lines/spans/segment.rs @@ -1,7 +1,7 @@ use crate::utils::span::{IndexedCow, Span, SpannedStr, SpannedText}; /// Refers to a part of a span -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Segment { /// ID of the span this segment refers to pub span_id: usize, diff --git a/cursive-core/src/utils/span.rs b/cursive-core/src/utils/span.rs index a9822cd..ac05014 100644 --- a/cursive-core/src/utils/span.rs +++ b/cursive-core/src/utils/span.rs @@ -8,14 +8,14 @@ use unicode_width::UnicodeWidthStr; /// A string with associated spans. /// /// Each span has an associated attribute `T`. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SpannedString { source: String, spans: Vec>, } /// The immutable, borrowed equivalent of `SpannedString`. -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Hash)] pub struct SpannedStr<'a, T> { source: &'a str, spans: &'a [IndexedSpan], @@ -261,7 +261,7 @@ impl<'a, T> From<&'a SpannedString> for SpannedStr<'a, T> { } /// An indexed span with an associated attribute. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct IndexedSpan { /// Content of the span. pub content: IndexedCow, @@ -280,7 +280,7 @@ impl AsRef for IndexedSpan { } /// A resolved span borrowing its source string. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Span<'a, T> { /// Content of this span. pub content: &'a str, @@ -334,7 +334,7 @@ impl IndexedSpan { } /// A span of text that can be either owned, or indexed in another String. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum IndexedCow { /// Indexes content in a separate string. Borrowed { diff --git a/cursive-core/src/view/margins.rs b/cursive-core/src/view/margins.rs index a97eba8..f30cb83 100644 --- a/cursive-core/src/view/margins.rs +++ b/cursive-core/src/view/margins.rs @@ -2,7 +2,7 @@ use crate::Vec2; use std::ops::{Add, Div, Mul, Sub}; /// Four values representing each direction. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct Margins { /// Left margin pub left: usize, diff --git a/cursive-core/src/view/position.rs b/cursive-core/src/view/position.rs index 732e6a5..12733d7 100644 --- a/cursive-core/src/view/position.rs +++ b/cursive-core/src/view/position.rs @@ -52,7 +52,7 @@ impl Position { } /// Single-dimensional offset policy. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)] pub enum Offset { /// In the center of the screen Center, diff --git a/cursive-core/src/view/size_constraint.rs b/cursive-core/src/view/size_constraint.rs index 2b3bf66..7905375 100644 --- a/cursive-core/src/view/size_constraint.rs +++ b/cursive-core/src/view/size_constraint.rs @@ -5,7 +5,7 @@ use std::cmp::min; /// This describes a possible behaviour for a [`ResizedView`]. /// /// [`ResizedView`]: crate::views::ResizedView -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum SizeConstraint { /// No constraint imposed, the child view's response is used. Free, diff --git a/cursive-core/src/views/dialog.rs b/cursive-core/src/views/dialog.rs index 429fdf1..26fe38a 100644 --- a/cursive-core/src/views/dialog.rs +++ b/cursive-core/src/views/dialog.rs @@ -14,7 +14,7 @@ use std::cmp::max; use unicode_width::UnicodeWidthStr; /// Identifies currently focused element in [`Dialog`]. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum DialogFocus { /// Content element focused Content, diff --git a/cursive-core/src/views/stack_view.rs b/cursive-core/src/views/stack_view.rs index e88fb5f..141228c 100644 --- a/cursive-core/src/views/stack_view.rs +++ b/cursive-core/src/views/stack_view.rs @@ -32,7 +32,7 @@ enum Placement { } /// Identifies a layer in a `StackView`. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum LayerPosition { /// Starts from the back (bottom) of the stack. FromBack(usize),