gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definitions

fix: clippy lints (#702)

da888af8336c498edd4fcff6d86d68dd685921ec · by Josh McKinney · (2 years ago) · parent 950a0eb13 · browse the tree at this commit

Semantic delta · 8

examples/cosmic_text.rs

examples/custom_tree_owned_partial.rs

  • body changed fn next

examples/custom_tree_owned_unsafe.rs

src/compute/mod.rs

src/style/flex.rs

src/tree/taffy_tree.rs

7 files · +51 −51

diff --git a/examples/cosmic_text.rs b/examples/cosmic_text.rs
index 1c5d1589c..85e0ef0c4 100644
--- a/examples/cosmic_text.rs
+++ b/examples/cosmic_text.rs
@@ -26,7 +26,7 @@ impl CosmicTextContext {
         font_system: &mut FontSystem,
     ) -> taffy::Size<f32> {
         // Set width constraint
-        let width_constraint = known_dimensions.width.or_else(|| match available_space.width {
+        let width_constraint = known_dimensions.width.or(match available_space.width {
             AvailableSpace::MinContent => Some(0.0),
             AvailableSpace::MaxContent => None,
             AvailableSpace::Definite(width) => Some(width),
diff --git a/examples/custom_tree_owned_partial.rs b/examples/custom_tree_owned_partial.rs
index f9fb37897..da77f3318 100644
--- a/examples/custom_tree_owned_partial.rs
+++ b/examples/custom_tree_owned_partial.rs
@@ -105,7 +105,7 @@ struct ChildIter(std::ops::Range<usize>);
 impl Iterator for ChildIter {
     type Item = NodeId;
     fn next(&mut self) -> Option<Self::Item> {
-        self.0.next().map(|idx| NodeId::from(idx))
+        self.0.next().map(NodeId::from)
     }
 }
 
diff --git a/examples/custom_tree_owned_unsafe.rs b/examples/custom_tree_owned_unsafe.rs
index c6bf0d24e..d41697b4c 100644
--- a/examples/custom_tree_owned_unsafe.rs
+++ b/examples/custom_tree_owned_unsafe.rs
@@ -88,7 +88,7 @@ impl Node {
     }
 
     pub fn print_tree(&mut self) {
-        print_tree(&mut StatelessLayoutTree, unsafe { self.as_id() });
+        print_tree(&StatelessLayoutTree, unsafe { self.as_id() });
     }
 }
 
diff --git a/src/compute/mod.rs b/src/compute/mod.rs
index 8a23c051e..1c6ba62a5 100644
--- a/src/compute/mod.rs
+++ b/src/compute/mod.rs
@@ -299,13 +299,13 @@ mod tests {
             )
             .unwrap();
 
-        compute_hidden_layout(&mut taffy.as_layout_tree(), root.into());
+        compute_hidden_layout(&mut taffy.as_layout_tree(), root);
 
         // Whatever size and display-mode the nodes had previously,
         // all layouts should resolve to ZERO due to the root's DISPLAY::NONE
 
         for node in [root, child_00, child_01, grandchild_00, grandchild_01, grandchild_02] {
-            let layout = taffy.layout(node.into()).unwrap();
+            let layout = taffy.layout(node).unwrap();
             assert_eq!(layout.size, Size::zero());
             assert_eq!(layout.location, Point::zero());
         }
diff --git a/src/style/flex.rs b/src/style/flex.rs
index f04f3a454..0bbcc8e8e 100644
--- a/src/style/flex.rs
+++ b/src/style/flex.rs
@@ -173,26 +173,26 @@ mod tests {
 
         #[test]
         fn flex_direction_is_row() {
-            assert_eq!(FlexDirection::Row.is_row(), true);
-            assert_eq!(FlexDirection::RowReverse.is_row(), true);
-            assert_eq!(FlexDirection::Column.is_row(), false);
-            assert_eq!(FlexDirection::ColumnReverse.is_row(), false);
+            assert!(FlexDirection::Row.is_row());
+            assert!(FlexDirection::RowReverse.is_row());
+            assert!(!FlexDirection::Column.is_row());
+            assert!(!FlexDirection::ColumnReverse.is_row());
         }
 
         #[test]
         fn flex_direction_is_column() {
-            assert_eq!(FlexDirection::Row.is_column(), false);
-            assert_eq!(FlexDirection::RowReverse.is_column(), false);
-            assert_eq!(FlexDirection::Column.is_column(), true);
-            assert_eq!(FlexDirection::ColumnReverse.is_column(), true);
+            assert!(!FlexDirection::Row.is_column());
+            assert!(!FlexDirection::RowReverse.is_column());
+            assert!(FlexDirection::Column.is_column());
+            assert!(FlexDirection::ColumnReverse.is_column());
         }
 
         #[test]
         fn flex_direction_is_reverse() {
-            assert_eq!(FlexDirection::Row.is_reverse(), false);
-            assert_eq!(FlexDirection::RowReverse.is_reverse(), true);
-            assert_eq!(FlexDirection::Column.is_reverse(), false);
-            assert_eq!(FlexDirection::ColumnReverse.is_reverse(), true);
+            assert!(!FlexDirection::Row.is_reverse());
+            assert!(FlexDirection::RowReverse.is_reverse());
+            assert!(!FlexDirection::Column.is_reverse());
+            assert!(FlexDirection::ColumnReverse.is_reverse());
         }
     }
 }
diff --git a/src/style_helpers.rs b/src/style_helpers.rs
index 9701a6a59..e499990b7 100644
--- a/src/style_helpers.rs
+++ b/src/style_helpers.rs
@@ -26,30 +26,6 @@ where
     TrackSizingFunction::Repeat(repetition_kind.try_into().unwrap(), track_list)
 }
 
-#[cfg(feature = "grid")]
-#[cfg(test)]
-mod repeat_fn_tests {
-    use super::repeat;
-    use crate::style::{GridTrackRepetition, NonRepeatedTrackSizingFunction, TrackSizingFunction};
-
-    const TEST_VEC: Vec<NonRepeatedTrackSizingFunction> = Vec::new();
-
-    #[test]
-    fn test_repeat_u16() {
-        assert_eq!(repeat(123, TEST_VEC), TrackSizingFunction::Repeat(GridTrackRepetition::Count(123), TEST_VEC));
-    }
-
-    #[test]
-    fn test_repeat_auto_fit_str() {
-        assert_eq!(repeat("auto-fit", TEST_VEC), TrackSizingFunction::Repeat(GridTrackRepetition::AutoFit, TEST_VEC));
-    }
-
-    #[test]
-    fn test_repeat_auto_fill_str() {
-        assert_eq!(repeat("auto-fill", TEST_VEC), TrackSizingFunction::Repeat(GridTrackRepetition::AutoFill, TEST_VEC));
-    }
-}
-
 #[cfg(feature = "grid")]
 /// Returns a grid template containing `count` evenly sized tracks
 pub fn evenly_sized_tracks(count: u16) -> Vec<TrackSizingFunction> {
@@ -544,3 +520,27 @@ pub trait FromFlex {
     /// Converts into an `Into<f32>` into Self
     fn from_flex<Input: Into<f32> + Copy>(flex: Input) -> Self;
 }
+
+#[cfg(feature = "grid")]
+#[cfg(test)]
+mod repeat_fn_tests {
+    use super::repeat;
+    use crate::style::{GridTrackRepetition, NonRepeatedTrackSizingFunction, TrackSizingFunction};
+
+    const TEST_VEC: Vec<NonRepeatedTrackSizingFunction> = Vec::new();
+
+    #[test]
+    fn test_repeat_u16() {
+        assert_eq!(repeat(123, TEST_VEC), TrackSizingFunction::Repeat(GridTrackRepetition::Count(123), TEST_VEC));
+    }
+
+    #[test]
+    fn test_repeat_auto_fit_str() {
+        assert_eq!(repeat("auto-fit", TEST_VEC), TrackSizingFunction::Repeat(GridTrackRepetition::AutoFit, TEST_VEC));
+    }
+
+    #[test]
+    fn test_repeat_auto_fill_str() {
+        assert_eq!(repeat("auto-fill", TEST_VEC), TrackSizingFunction::Repeat(GridTrackRepetition::AutoFill, TEST_VEC));
+    }
+}
diff --git a/src/tree/taffy_tree.rs b/src/tree/taffy_tree.rs
index 2c7b4e156..aabb8495e 100644
--- a/src/tree/taffy_tree.rs
+++ b/src/tree/taffy_tree.rs
@@ -28,7 +28,7 @@ use crate::{compute::compute_grid_layout, LayoutGridContainer};
 pub type TaffyResult<T> = Result<T, TaffyError>;
 
 /// An error that occurs while trying to access or modify a node's children by index.
-#[derive(Debug)]
+#[derive(Debug, Clone, PartialEq, Eq)]
 pub enum TaffyError {
     /// The parent node does not have a child at `child_index`. It only has `child_count` children
     ChildIndexOutOfBounds {
@@ -1131,20 +1131,20 @@ mod tests {
 
         taffy.compute_layout(node, Size::MAX_CONTENT).unwrap();
 
-        assert_eq!(taffy.dirty(child0).unwrap(), false);
-        assert_eq!(taffy.dirty(child1).unwrap(), false);
-        assert_eq!(taffy.dirty(node).unwrap(), false);
+        assert_eq!(taffy.dirty(child0), Ok(false));
+        assert_eq!(taffy.dirty(child1), Ok(false));
+        assert_eq!(taffy.dirty(node), Ok(false));
 
         taffy.mark_dirty(node).unwrap();
-        assert_eq!(taffy.dirty(child0).unwrap(), false);
-        assert_eq!(taffy.dirty(child1).unwrap(), false);
-        assert_eq!(taffy.dirty(node).unwrap(), true);
+        assert_eq!(taffy.dirty(child0), Ok(false));
+        assert_eq!(taffy.dirty(child1), Ok(false));
+        assert_eq!(taffy.dirty(node), Ok(true));
 
         taffy.compute_layout(node, Size::MAX_CONTENT).unwrap();
         taffy.mark_dirty(child0).unwrap();
-        assert_eq!(taffy.dirty(child0).unwrap(), true);
-        assert_eq!(taffy.dirty(child1).unwrap(), false);
-        assert_eq!(taffy.dirty(node).unwrap(), true);
+        assert_eq!(taffy.dirty(child0), Ok(true));
+        assert_eq!(taffy.dirty(child1), Ok(false));
+        assert_eq!(taffy.dirty(node), Ok(true));
     }
 
     #[test]