Fix clippy lints

This commit is contained in:
Danny McGee
2023-12-19 17:25:33 -05:00
parent 0dc07e9608
commit 15fd44d7e0
8 changed files with 64 additions and 64 deletions
+2 -2
View File
@@ -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)
+9 -2
View File
@@ -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<T: Clone + Default>(vec: &mut Vec<T>, 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);
}
+1 -2
View File
@@ -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
+7 -13
View File
@@ -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<Vec<u8>> for JointName {
impl From<&'_ [u8]> for JointName {
#[inline]
fn from(s: &'_ [u8]) -> Self {
JointName(s.into_iter().copied().collect::<JointNameInner>())
JointName(s.iter().copied().collect::<JointNameInner>())
}
}
@@ -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`.
+4 -4
View File
@@ -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
+15 -13
View File
@@ -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]
+3 -3
View File
@@ -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 {
+23 -25
View File
@@ -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<usize>,
#[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<Joint<'a>>,
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 }
}
}