Skip to content

Commit

Permalink
fix: clippy lints (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshka authored Aug 3, 2024
1 parent 950a0eb commit da888af
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/cosmic_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_tree_owned_partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_tree_owned_unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
24 changes: 12 additions & 12 deletions src/style/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
48 changes: 24 additions & 24 deletions src/style_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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));
}
}
20 changes: 10 additions & 10 deletions src/tree/taffy_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit da888af

Please sign in to comment.