From 0dd4ae0a7ac0c247078df492469ff20b8a90c886 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 21 Aug 2021 16:38:51 +0200 Subject: Prune derives --- src/layout/tree.rs | 60 +++--------------------------------------------------- 1 file changed, 3 insertions(+), 57 deletions(-) (limited to 'src/layout/tree.rs') diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 1899a4d2..05f94c38 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -1,7 +1,6 @@ use super::*; use std::any::Any; -use std::fmt::{self, Debug, Formatter}; #[cfg(feature = "layout-cache")] use std::hash::{Hash, Hasher}; @@ -10,7 +9,6 @@ use std::hash::{Hash, Hasher}; use fxhash::FxHasher64; /// A tree of layout nodes. -#[derive(Debug, Clone, Eq, PartialEq)] pub struct LayoutTree { /// Runs of pages with the same properties. pub runs: Vec, @@ -24,7 +22,6 @@ impl LayoutTree { } /// A run of pages that all have the same properties. -#[derive(Debug, Clone, Eq, PartialEq)] pub struct PageRun { /// The size of each page. pub size: Size, @@ -47,7 +44,7 @@ impl PageRun { /// A dynamic layouting node. pub struct LayoutNode { - node: Box, + node: Box, #[cfg(feature = "layout-cache")] hash: u64, } @@ -57,7 +54,7 @@ impl LayoutNode { #[cfg(not(feature = "layout-cache"))] pub fn new(node: T) -> Self where - T: Layout + Debug + Clone + Eq + PartialEq + 'static, + T: Layout + 'static, { Self { node: Box::new(node) } } @@ -66,7 +63,7 @@ impl LayoutNode { #[cfg(feature = "layout-cache")] pub fn new(node: T) -> Self where - T: Layout + Debug + Clone + Eq + PartialEq + Hash + 'static, + T: Layout + Hash + 'static, { let hash = { let mut state = FxHasher64::default(); @@ -99,60 +96,9 @@ impl Layout for LayoutNode { } } -impl Debug for LayoutNode { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - self.node.fmt(f) - } -} - -impl Clone for LayoutNode { - fn clone(&self) -> Self { - Self { - node: self.node.dyn_clone(), - #[cfg(feature = "layout-cache")] - hash: self.hash, - } - } -} - -impl Eq for LayoutNode {} - -impl PartialEq for LayoutNode { - fn eq(&self, other: &Self) -> bool { - self.node.dyn_eq(other.node.as_ref()) - } -} - #[cfg(feature = "layout-cache")] impl Hash for LayoutNode { fn hash(&self, state: &mut H) { state.write_u64(self.hash); } } - -trait Bounds: Layout + Debug + 'static { - fn as_any(&self) -> &dyn Any; - fn dyn_eq(&self, other: &dyn Bounds) -> bool; - fn dyn_clone(&self) -> Box; -} - -impl Bounds for T -where - T: Layout + Debug + Eq + PartialEq + Clone + 'static, -{ - fn as_any(&self) -> &dyn Any { - self - } - - fn dyn_eq(&self, other: &dyn Bounds) -> bool { - if let Some(other) = other.as_any().downcast_ref::() { - self == other - } else { - false - } - } - - fn dyn_clone(&self) -> Box { - Box::new(self.clone()) - } -} -- cgit v1.2.3