summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-08 23:16:02 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-08 23:16:02 +0200
commit02b586cc36fad58a622ecb439e1cf3a76a347207 (patch)
tree11ec37daa234e19e9eb30e0370795e77e4ef418b /src
parentfd0b89a1d8e4f811fcf3517d321a327a0cf72edf (diff)
Add lots of Eq impls
Diffstat (limited to 'src')
-rw-r--r--src/exec/state.rs12
-rw-r--r--src/font.rs24
-rw-r--r--src/layout/background.rs2
-rw-r--r--src/layout/fixed.rs2
-rw-r--r--src/layout/frame.rs12
-rw-r--r--src/layout/grid.rs4
-rw-r--r--src/layout/image.rs2
-rw-r--r--src/layout/incremental.rs4
-rw-r--r--src/layout/mod.rs12
-rw-r--r--src/layout/pad.rs2
-rw-r--r--src/layout/par.rs4
-rw-r--r--src/layout/stack.rs4
-rw-r--r--src/paper.rs4
-rw-r--r--src/syntax/token.rs8
14 files changed, 51 insertions, 45 deletions
diff --git a/src/exec/state.rs b/src/exec/state.rs
index cbd65622..f99a8901 100644
--- a/src/exec/state.rs
+++ b/src/exec/state.rs
@@ -8,7 +8,7 @@ use crate::layout::Paint;
use crate::paper::{Paper, PaperClass, PAPER_A4};
/// The execution state.
-#[derive(Default, Debug, Clone, PartialEq, Hash)]
+#[derive(Default, Debug, Clone, Eq, PartialEq, Hash)]
pub struct State {
/// The current language-related settings.
pub lang: LangState,
@@ -30,7 +30,7 @@ impl State {
}
/// Defines language properties.
-#[derive(Debug, Copy, Clone, PartialEq, Hash)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct LangState {
/// The direction for text and other inline objects.
pub dir: Dir,
@@ -43,7 +43,7 @@ impl Default for LangState {
}
/// Defines page properties.
-#[derive(Debug, Copy, Clone, PartialEq, Hash)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct PageState {
/// The class of this page.
pub class: PaperClass,
@@ -83,7 +83,7 @@ impl Default for PageState {
}
/// Defines paragraph properties.
-#[derive(Debug, Copy, Clone, PartialEq, Hash)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct ParState {
/// The spacing between paragraphs (dependent on scaled font size).
pub spacing: Linear,
@@ -105,7 +105,7 @@ impl Default for ParState {
}
/// Defines font properties.
-#[derive(Debug, Clone, PartialEq, Hash)]
+#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct FontState {
/// A list of font families with generic class definitions.
pub families: Rc<FamilyList>,
@@ -163,7 +163,7 @@ impl Default for FontState {
}
/// Describes a line that could be positioned over, under or on top of text.
-#[derive(Debug, Copy, Clone, PartialEq, Hash)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct LineState {
/// Stroke color of the line.
///
diff --git a/src/font.rs b/src/font.rs
index fc7a99d9..d63c4c1b 100644
--- a/src/font.rs
+++ b/src/font.rs
@@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::fmt::{self, Debug, Display, Formatter};
use std::ops::Add;
+use decorum::N64;
use serde::{Deserialize, Serialize};
use crate::geom::Length;
@@ -119,7 +120,7 @@ impl Face {
VerticalFontMetric::Ascender => self.ascender,
VerticalFontMetric::CapHeight => self.cap_height,
VerticalFontMetric::XHeight => self.x_height,
- VerticalFontMetric::Baseline => Em::ZERO,
+ VerticalFontMetric::Baseline => Em::zero(),
VerticalFontMetric::Descender => self.descender,
}
}
@@ -161,31 +162,33 @@ impl Display for VerticalFontMetric {
/// A length in em units.
///
/// `1em` is the same as the font size.
-#[derive(Default, Debug, Copy, Clone, PartialEq, PartialOrd)]
-pub struct Em(f64);
+#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, PartialOrd)]
+pub struct Em(N64);
impl Em {
/// The zero length.
- pub const ZERO: Self = Self(0.0);
+ pub fn zero() -> Self {
+ Self(N64::from(0.0))
+ }
/// Create an em length.
pub fn new(em: f64) -> Self {
- Self(em)
+ Self(N64::from(em))
}
/// Convert units to an em length at the given units per em.
pub fn from_units(units: impl Into<f64>, units_per_em: f64) -> Self {
- Self(units.into() / units_per_em)
+ Self(N64::from(units.into() / units_per_em))
}
/// The number of em units.
pub fn get(self) -> f64 {
- self.0
+ self.0.into()
}
/// Convert to a length at the given font size.
pub fn to_length(self, font_size: Length) -> Length {
- self.0 * font_size
+ self.get() * font_size
}
}
@@ -317,7 +320,7 @@ impl FaceId {
}
/// Properties of a single font face.
-#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct FaceInfo {
/// The typographic font family this face is part of.
pub family: String,
@@ -330,7 +333,8 @@ pub struct FaceInfo {
}
/// Properties that distinguish a face from other faces in the same family.
-#[derive(Default, Debug, Copy, Clone, PartialEq, Hash, Serialize, Deserialize)]
+#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Hash)]
+#[derive(Serialize, Deserialize)]
pub struct FontVariant {
/// The style of the face (normal / italic / oblique).
pub style: FontStyle,
diff --git a/src/layout/background.rs b/src/layout/background.rs
index 0e93c06f..867783bf 100644
--- a/src/layout/background.rs
+++ b/src/layout/background.rs
@@ -1,7 +1,7 @@
use super::*;
/// A node that places a rectangular filled background behind its child.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "layout-cache", derive(Hash))]
pub struct BackgroundNode {
/// The kind of shape to use as a background.
diff --git a/src/layout/fixed.rs b/src/layout/fixed.rs
index c1d1ac5e..dfcd4038 100644
--- a/src/layout/fixed.rs
+++ b/src/layout/fixed.rs
@@ -1,7 +1,7 @@
use super::*;
/// A node that can fix its child's width and height.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "layout-cache", derive(Hash))]
pub struct FixedNode {
/// The fixed width, if any.
diff --git a/src/layout/frame.rs b/src/layout/frame.rs
index 65a55857..862dc4be 100644
--- a/src/layout/frame.rs
+++ b/src/layout/frame.rs
@@ -9,7 +9,7 @@ use crate::geom::{Length, Path, Point, Size};
use crate::image::ImageId;
/// A finished layout with elements at fixed positions.
-#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[derive(Default, Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Frame {
/// The size of the frame.
pub size: Size,
@@ -99,14 +99,14 @@ impl Frame {
/// A frame can contain multiple children: elements or other frames, complete
/// with their children.
-#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
enum Child {
Element(Element),
Frame(Rc<Frame>),
}
/// The building block frames are composed of.
-#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub enum Element {
/// Shaped text.
Text(Text),
@@ -118,7 +118,7 @@ pub enum Element {
}
/// A run of shaped text.
-#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Text {
/// The font face the glyphs are contained in.
pub face_id: FaceId,
@@ -131,7 +131,7 @@ pub struct Text {
}
/// A glyph in a run of shaped text.
-#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Glyph {
/// The glyph's index in the face.
pub id: u16,
@@ -155,7 +155,7 @@ impl Text {
}
/// A geometric shape.
-#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub enum Geometry {
/// A filled rectangle with its origin in the topleft corner.
Rect(Size),
diff --git a/src/layout/grid.rs b/src/layout/grid.rs
index b0bf225f..06b6596c 100644
--- a/src/layout/grid.rs
+++ b/src/layout/grid.rs
@@ -1,7 +1,7 @@
use super::*;
/// A node that arranges its children in a grid.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "layout-cache", derive(Hash))]
pub struct GridNode {
/// The `main` and `cross` directions of this grid.
@@ -18,7 +18,7 @@ pub struct GridNode {
}
/// Defines how to size a grid cell along an axis.
-#[derive(Debug, Copy, Clone, PartialEq, Hash)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum TrackSizing {
/// Fit the cell to its contents.
Auto,
diff --git a/src/layout/image.rs b/src/layout/image.rs
index 20a521ff..9ea9db55 100644
--- a/src/layout/image.rs
+++ b/src/layout/image.rs
@@ -4,7 +4,7 @@ use crate::image::ImageId;
use ::image::GenericImageView;
/// An image node.
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "layout-cache", derive(Hash))]
pub struct ImageNode {
/// The id of the image file.
diff --git a/src/layout/incremental.rs b/src/layout/incremental.rs
index d41fe431..429dc514 100644
--- a/src/layout/incremental.rs
+++ b/src/layout/incremental.rs
@@ -168,7 +168,7 @@ impl FramesEntry {
}
/// Describe regions that match them.
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Constraints {
/// The minimum available length in the region.
pub min: Spec<Option<Length>>,
@@ -253,7 +253,7 @@ impl Constraints {
/// Carries an item that only applies to certain regions and the constraints
/// that describe these regions.
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct Constrained<T> {
pub item: T,
pub constraints: Constraints,
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index e8bdab62..bf6c8092 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -51,7 +51,7 @@ pub fn layout(
}
/// A tree of layout nodes.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, Eq, PartialEq)]
pub struct LayoutTree {
/// Runs of pages with the same properties.
pub runs: Vec<PageRun>,
@@ -65,7 +65,7 @@ impl LayoutTree {
}
/// A run of pages that all have the same properties.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, Eq, PartialEq)]
pub struct PageRun {
/// The size of each page.
pub size: Size,
@@ -98,7 +98,7 @@ impl AnyNode {
#[cfg(feature = "layout-cache")]
pub fn new<T>(node: T) -> Self
where
- T: Layout + Debug + Clone + PartialEq + Hash + 'static,
+ T: Layout + Debug + Clone + Eq + PartialEq + Hash + 'static,
{
let hash = {
let mut state = FxHasher64::default();
@@ -153,6 +153,8 @@ impl Clone for AnyNode {
}
}
+impl Eq for AnyNode {}
+
impl PartialEq for AnyNode {
fn eq(&self, other: &Self) -> bool {
self.node.dyn_eq(other.node.as_ref())
@@ -180,7 +182,7 @@ trait Bounds: Layout + Debug + 'static {
impl<T> Bounds for T
where
- T: Layout + Debug + PartialEq + Clone + 'static,
+ T: Layout + Debug + Eq + PartialEq + Clone + 'static,
{
fn as_any(&self) -> &dyn Any {
self
@@ -221,7 +223,7 @@ pub struct LayoutContext<'a> {
}
/// A sequence of regions to layout into.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Regions {
/// The remaining size of the current region.
pub current: Size,
diff --git a/src/layout/pad.rs b/src/layout/pad.rs
index 75ed366c..3770c754 100644
--- a/src/layout/pad.rs
+++ b/src/layout/pad.rs
@@ -1,7 +1,7 @@
use super::*;
/// A node that adds padding to its child.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "layout-cache", derive(Hash))]
pub struct PadNode {
/// The amount of padding.
diff --git a/src/layout/par.rs b/src/layout/par.rs
index 34016737..5d21e05e 100644
--- a/src/layout/par.rs
+++ b/src/layout/par.rs
@@ -11,7 +11,7 @@ use crate::util::{RangeExt, SliceExt};
type Range = std::ops::Range<usize>;
/// A node that arranges its children into a paragraph.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "layout-cache", derive(Hash))]
pub struct ParNode {
/// The inline direction of this paragraph.
@@ -23,7 +23,7 @@ pub struct ParNode {
}
/// A child of a paragraph node.
-#[derive(Clone, PartialEq)]
+#[derive(Clone, Eq, PartialEq)]
#[cfg_attr(feature = "layout-cache", derive(Hash))]
pub enum ParChild {
/// Spacing between other nodes.
diff --git a/src/layout/stack.rs b/src/layout/stack.rs
index d8e30b2a..516a2284 100644
--- a/src/layout/stack.rs
+++ b/src/layout/stack.rs
@@ -3,7 +3,7 @@ use decorum::N64;
use super::*;
/// A node that stacks its children.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "layout-cache", derive(Hash))]
pub struct StackNode {
/// The `main` and `cross` directions of this stack.
@@ -20,7 +20,7 @@ pub struct StackNode {
}
/// A child of a stack node.
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "layout-cache", derive(Hash))]
pub enum StackChild {
/// Spacing between other nodes.
diff --git a/src/paper.rs b/src/paper.rs
index 8dfc071c..03c48f16 100644
--- a/src/paper.rs
+++ b/src/paper.rs
@@ -8,9 +8,9 @@ pub struct Paper {
/// The broad class this paper belongs to.
pub class: PaperClass,
/// The width of the paper in millimeters.
- pub width: f64,
+ width: f64,
/// The height of the paper in millimeters.
- pub height: f64,
+ height: f64,
}
impl Paper {
diff --git a/src/syntax/token.rs b/src/syntax/token.rs
index c14cf9f7..567782e7 100644
--- a/src/syntax/token.rs
+++ b/src/syntax/token.rs
@@ -157,7 +157,7 @@ pub enum Token<'s> {
}
/// A quoted string token: `"..."`.
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct StrToken<'s> {
/// The string inside the quotes.
///
@@ -170,7 +170,7 @@ pub struct StrToken<'s> {
}
/// A raw block token: `` `...` ``.
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct RawToken<'s> {
/// The raw text between the backticks.
pub text: &'s str,
@@ -181,7 +181,7 @@ pub struct RawToken<'s> {
}
/// A math formula token: `$2pi + x$` or `$[f'(x) = x^2]$`.
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct MathToken<'s> {
/// The formula between the dollars.
pub formula: &'s str,
@@ -193,7 +193,7 @@ pub struct MathToken<'s> {
}
/// A unicode escape sequence token: `\u{1F5FA}`.
-#[derive(Debug, Copy, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct UnicodeEscapeToken<'s> {
/// The escape sequence between the braces.
pub sequence: &'s str,