From 15fd44d7e0eba5a831f86055b4f47ad863981888 Mon Sep 17 00:00:00 2001 From: Danny McGee Date: Tue, 19 Dec 2023 17:25:33 -0500 Subject: [PATCH] Fix `clippy` lints --- studio-bvh/src/errors.rs | 4 +-- studio-bvh/src/frame_cursor.rs | 11 ++++++-- studio-bvh/src/frame_iter.rs | 3 +-- studio-bvh/src/joint.rs | 20 +++++--------- studio-bvh/src/lib.rs | 8 +++--- studio-bvh/src/macros.rs | 28 +++++++++++--------- studio-bvh/src/parse.rs | 6 ++--- studio-bvh/src/write.rs | 48 ++++++++++++++++------------------ 8 files changed, 64 insertions(+), 64 deletions(-) diff --git a/studio-bvh/src/errors.rs b/studio-bvh/src/errors.rs index 1359c52..2d39472 100644 --- a/studio-bvh/src/errors.rs +++ b/studio-bvh/src/errors.rs @@ -302,7 +302,7 @@ impl fmt::Display for LoadMotionError { ref parse_error, line, } => { - if let Some(_) = parse_error { + if parse_error.is_some() { write!(fmtr, "{}: could not parse the num frames value", line) } else { write!( @@ -316,7 +316,7 @@ impl fmt::Display for LoadMotionError { ref parse_error, line, } => { - if let Some(_) = parse_error { + if parse_error.is_some() { write!(fmtr, "{}: could not parse the frame time", line) } else { write!(fmtr, "{}: Could not parse the frame time", line) diff --git a/studio-bvh/src/frame_cursor.rs b/studio-bvh/src/frame_cursor.rs index 7835fe2..dd81f58 100644 --- a/studio-bvh/src/frame_cursor.rs +++ b/studio-bvh/src/frame_cursor.rs @@ -36,6 +36,13 @@ impl<'bvh> FrameCursor<'bvh> { self.bvh.frames().len() } + #[must_use] + #[inline(always)] + #[allow(missing_docs)] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// Returns the number of channels in the [`Bvh`] the cursor is is currently /// pointing to. /// @@ -403,7 +410,7 @@ impl<'bvh> FrameCursor<'bvh> { /// # } // fn main() /// ``` pub fn remove_frame(&mut self) -> Result<&mut Self, FrameRemoveError> { - if self.len() == 0 { + if self.is_empty() { return Err(FrameRemoveError::new(self.index)); } @@ -567,7 +574,7 @@ fn vec_insert_slice(vec: &mut Vec, index: usize, slice: & vec.resize_with(new_len, T::default); // Move the existing items to the end - for (to_move, end_index) in (index..old_len).into_iter().zip(old_len + index..new_len) { + for (to_move, end_index) in (index..old_len).zip(old_len + index..new_len) { vec.swap(to_move, end_index); } diff --git a/studio-bvh/src/frame_iter.rs b/studio-bvh/src/frame_iter.rs index d86aa27..18ef86a 100644 --- a/studio-bvh/src/frame_iter.rs +++ b/studio-bvh/src/frame_iter.rs @@ -144,7 +144,7 @@ impl<'a> AsRef<[f32]> for Frame<'a> { impl<'a> Borrow<[f32]> for Frame<'a> { #[inline] fn borrow(&self) -> &[f32] { - &*self.0 + self.0 } } @@ -308,7 +308,6 @@ macro_rules! impl_channel_frame_index { impl FrameIndex for $chn { type SliceIndex = usize; - #[inline] #[inline] fn to_slice_index(self) -> Self::SliceIndex { self.motion_index diff --git a/studio-bvh/src/joint.rs b/studio-bvh/src/joint.rs index 63afa62..08339c0 100644 --- a/studio-bvh/src/joint.rs +++ b/studio-bvh/src/joint.rs @@ -45,18 +45,12 @@ pub(crate) enum JointData { impl JointData { #[inline] pub(crate) const fn is_root(&self) -> bool { - match *self { - JointData::Root { .. } => true, - _ => false, - } + matches!(*self, JointData::Root { .. }) } #[inline] pub(crate) const fn is_child(&self) -> bool { - match *self { - JointData::Child { .. } => true, - _ => false, - } + matches!(*self, JointData::Child { .. }) } #[inline] @@ -143,7 +137,7 @@ impl JointData { pub(crate) fn empty_root() -> Self { JointData::Root { name: Default::default(), - offset: [0.0, 0.0, 0.0].into(), + offset: [0.0, 0.0, 0.0], channels: Default::default(), } } @@ -152,7 +146,7 @@ impl JointData { pub(crate) fn empty_child() -> Self { JointData::Child { name: Default::default(), - offset: [0.0, 0.0, 0.0].into(), + offset: [0.0, 0.0, 0.0], channels: Default::default(), end_site_offset: Default::default(), private: JointPrivateData::empty(), @@ -193,7 +187,7 @@ impl JointData { } => *channels = new_channels, JointData::Child { ref mut channels, .. - } => *channels = new_channels.iter().map(|c| *c).collect(), + } => *channels = new_channels.iter().copied().collect(), } } @@ -291,7 +285,7 @@ impl From> for JointName { impl From<&'_ [u8]> for JointName { #[inline] fn from(s: &'_ [u8]) -> Self { - JointName(s.into_iter().copied().collect::()) + JointName(s.iter().copied().collect::()) } } @@ -790,7 +784,7 @@ impl Joint<'_> { /// Returns an iterator over the children of `self`. #[inline] pub fn children(&self) -> Joints<'_> { - Joints::iter_children(&self) + Joints::iter_children(self) } /// Access a read-only view of the internal data of the `Joint`. diff --git a/studio-bvh/src/lib.rs b/studio-bvh/src/lib.rs index 3b8cebe..1c0a05f 100644 --- a/studio-bvh/src/lib.rs +++ b/studio-bvh/src/lib.rs @@ -814,10 +814,10 @@ impl ChannelType { /// ``` #[inline] pub const fn is_rotation(&self) -> bool { - match *self { - ChannelType::RotationX | ChannelType::RotationY | ChannelType::RotationZ => true, - _ => false, - } + matches!( + *self, + ChannelType::RotationX | ChannelType::RotationY | ChannelType::RotationZ + ) } /// Returns `true` if this channel corresponds to a positional diff --git a/studio-bvh/src/macros.rs b/studio-bvh/src/macros.rs index fef8550..ed9b305 100644 --- a/studio-bvh/src/macros.rs +++ b/studio-bvh/src/macros.rs @@ -461,25 +461,27 @@ impl BvhLiteralBuilder { pub fn push_channel(&mut self, channel: ChannelType) { let channel = Channel::new(channel, self.current_channel_index); - self.last_joint().map(|joint| match *joint { - JointData::Root { - ref mut channels, .. - } => { - channels.push(channel); + if let Some(joint) = self.last_joint() { + match *joint { + JointData::Root { + ref mut channels, .. + } => { + channels.push(channel); + } + JointData::Child { + ref mut channels, .. + } => { + channels.push(channel); + } } - JointData::Child { - ref mut channels, .. - } => { - channels.push(channel); - } - }); + } self.current_channel_index += 1; } pub fn push_joint_offset(&mut self, offset: Offset, is_end_site: bool) { - self.last_joint().map(|joint| { + if let Some(joint) = self.last_joint() { joint.set_offset(offset, is_end_site); - }); + } } #[inline] diff --git a/studio-bvh/src/parse.rs b/studio-bvh/src/parse.rs index 48d7f0e..54414fb 100644 --- a/studio-bvh/src/parse.rs +++ b/studio-bvh/src/parse.rs @@ -432,7 +432,7 @@ impl Bvh { let mut channels: SmallVec<[Channel; 6]> = Default::default(); channels.reserve(num_channels); - while let Some(tok) = tokens.next() { + for tok in tokens { let channel_ty = ChannelType::try_from(tok).map_err(|e| { LoadJointsError::ParseChannelError { error: e, @@ -548,7 +548,7 @@ impl Bvh { let mut tokens = line.fields(); let frame_time_kw = tokens.next(); - if frame_time_kw == FRAME_TIME_KEYWORDS.get(0).map(|b| *b) { + if frame_time_kw == FRAME_TIME_KEYWORDS.get(0).copied() { // do nothing } else { return Err(LoadMotionError::MissingFrameTime { @@ -558,7 +558,7 @@ impl Bvh { } let frame_time_kw = tokens.next(); - if frame_time_kw == FRAME_TIME_KEYWORDS.get(1).map(|b| *b) { + if frame_time_kw == FRAME_TIME_KEYWORDS.get(1).copied() { // do nothing } else { return Err(LoadMotionError::MissingFrameTime { diff --git a/studio-bvh/src/write.rs b/studio-bvh/src/write.rs index 688356c..3b94bd9 100644 --- a/studio-bvh/src/write.rs +++ b/studio-bvh/src/write.rs @@ -11,6 +11,7 @@ use std::{ /// Specify formatting options for writing a `Bvh`. #[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[non_exhaustive] pub struct WriteOptions { /// Which indentation style to use for nested bones. pub indent: IndentStyle, @@ -28,8 +29,6 @@ pub struct WriteOptions { /// /// If this is `None`, then the minimum precision required will be used pub motion_values_significant_figures: Option, - #[doc(hidden)] - _nonexhaustive: (), } impl Default for WriteOptions { @@ -49,7 +48,6 @@ impl WriteOptions { offset_significant_figures: None, frame_time_significant_figures: None, motion_values_significant_figures: None, - _nonexhaustive: (), } } @@ -60,7 +58,7 @@ impl WriteOptions { let mut curr_string_len = 0usize; let mut iter_state = WriteOptionsIterState::new(); - while self.next_chunk(bvh, &mut curr_chunk, &mut iter_state) != false { + while self.next_chunk(bvh, &mut curr_chunk, &mut iter_state) { let bytes: &[u8] = curr_chunk.as_ref(); curr_string_len += bytes.len(); curr_bytes_written += writer.write(bytes)?; @@ -81,8 +79,8 @@ impl WriteOptions { let mut out_string = vec![]; let mut iter_state = WriteOptionsIterState::new(); - while self.next_chunk(bvh, &mut curr_chunk, &mut iter_state) != false { - out_string.extend(curr_chunk.drain(..)); + while self.next_chunk(bvh, &mut curr_chunk, &mut iter_state) { + out_string.append(&mut curr_chunk); } out_string @@ -162,14 +160,14 @@ impl WriteOptions { let terminator = self.line_terminator.as_bytes(); match *iter_state { - WriteOptionsIterState::WriteHierarchy { ref mut written } => { + WriteOptionsIterState::Hierarchy { ref mut written } => { if !*written { *chunk = b"HIERARCHY".to_vec(); chunk.extend_from_slice(self.line_terminator.as_bytes()); *written = true; } else { let mut joints = bvh.joints(); - *iter_state = WriteOptionsIterState::WriteJoints { + *iter_state = WriteOptionsIterState::Joints { current_joint: joints.next(), joints, wrote_name: false, @@ -178,13 +176,13 @@ impl WriteOptions { }; } } - WriteOptionsIterState::WriteJoints { + WriteOptionsIterState::Joints { current_joint: None, .. } => { - *iter_state = WriteOptionsIterState::WriteMotion { written: false }; + *iter_state = WriteOptionsIterState::Motion { written: false }; } - WriteOptionsIterState::WriteJoints { + WriteOptionsIterState::Joints { ref mut joints, ref mut current_joint, ref mut wrote_name, @@ -296,25 +294,25 @@ impl WriteOptions { } } } - WriteOptionsIterState::WriteMotion { ref mut written } => { + WriteOptionsIterState::Motion { ref mut written } => { if !*written { *chunk = b"MOTION".to_vec(); chunk.extend_from_slice(terminator); *written = true; } else { - *iter_state = WriteOptionsIterState::WriteNumFrames { written: false }; + *iter_state = WriteOptionsIterState::NumFrames { written: false }; } } - WriteOptionsIterState::WriteNumFrames { ref mut written } => { + WriteOptionsIterState::NumFrames { ref mut written } => { if !*written { *chunk = format!("Frames: {}", bvh.frames().len()).into_bytes(); chunk.extend_from_slice(terminator); *written = true; } else { - *iter_state = WriteOptionsIterState::WriteFrameTime { written: false }; + *iter_state = WriteOptionsIterState::FrameTime { written: false }; } } - WriteOptionsIterState::WriteFrameTime { ref mut written } => { + WriteOptionsIterState::FrameTime { ref mut written } => { if !*written { *chunk = match self.frame_time_significant_figures { Some(sf) => { @@ -329,10 +327,10 @@ impl WriteOptions { *written = true; } else { let frames = bvh.frames(); - *iter_state = WriteOptionsIterState::WriteFrames { frames }; + *iter_state = WriteOptionsIterState::Frames { frames }; } } - WriteOptionsIterState::WriteFrames { ref mut frames } => { + WriteOptionsIterState::Frames { ref mut frames } => { return frames .next() .map(|frame| { @@ -358,26 +356,26 @@ impl WriteOptions { } enum WriteOptionsIterState<'a> { - WriteHierarchy { + Hierarchy { written: bool, }, - WriteJoints { + Joints { joints: Joints<'a>, current_joint: Option>, wrote_name: bool, wrote_offset: bool, wrote_channels: bool, }, - WriteMotion { + Motion { written: bool, }, - WriteNumFrames { + NumFrames { written: bool, }, - WriteFrameTime { + FrameTime { written: bool, }, - WriteFrames { + Frames { frames: Frames<'a>, }, } @@ -385,7 +383,7 @@ enum WriteOptionsIterState<'a> { impl WriteOptionsIterState<'_> { #[inline] const fn new() -> Self { - WriteOptionsIterState::WriteHierarchy { written: false } + WriteOptionsIterState::Hierarchy { written: false } } }