From ad15bdcafb0236de0adb52c5516b1e1c0d0d12af Mon Sep 17 00:00:00 2001 From: Shute052 Date: Mon, 29 Apr 2024 08:11:49 +0800 Subject: [PATCH] Prefer `FromIter<*AxisProcessor>` over `From>` --- examples/input_processing.rs | 2 +- src/input_processing/dual_axis/mod.rs | 16 ++++++++-------- src/input_processing/mod.rs | 4 ++-- src/input_processing/single_axis/mod.rs | 22 +++++++++++----------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/input_processing.rs b/examples/input_processing.rs index d1c6407b..e4ba17d0 100644 --- a/examples/input_processing.rs +++ b/examples/input_processing.rs @@ -46,7 +46,7 @@ fn spawn_player(mut commands: Commands) { .insert( Action::LookAround, // You can also use a sequence of processors as the processing pipeline. - DualAxis::mouse_motion().replace_processor(DualAxisProcessor::from(vec![ + DualAxis::mouse_motion().replace_processor(DualAxisProcessor::from_iter([ // The first processor is a circular deadzone. CircleDeadZone::new(0.1).into(), // The next processor doubles inputs normalized by the deadzone. diff --git a/src/input_processing/dual_axis/mod.rs b/src/input_processing/dual_axis/mod.rs index 8cb83b21..d721b018 100644 --- a/src/input_processing/dual_axis/mod.rs +++ b/src/input_processing/dual_axis/mod.rs @@ -72,7 +72,7 @@ pub enum DualAxisProcessor { /// /// assert_eq!( /// expected, - /// DualAxisProcessor::from(vec![ + /// DualAxisProcessor::from_iter([ /// DualAxisInverted::ALL.into(), /// DualAxisSensitivity::all(2.0).into(), /// ]) @@ -136,9 +136,9 @@ impl DualAxisProcessor { } } -impl From> for DualAxisProcessor { - fn from(value: Vec) -> Self { - Self::Pipeline(value.into_iter().map(Arc::new).collect()) +impl FromIterator for DualAxisProcessor { + fn from_iter>(iter: T) -> Self { + Self::Pipeline(iter.into_iter().map(Arc::new).collect()) } } @@ -313,19 +313,19 @@ mod tests { } #[test] - fn test_dual_axis_processor_from_list() { + fn test_dual_axis_processor_from_iter() { assert_eq!( - DualAxisProcessor::from(vec![]), + DualAxisProcessor::from_iter([]), DualAxisProcessor::Pipeline(vec![]) ); assert_eq!( - DualAxisProcessor::from(vec![DualAxisInverted::ALL.into()]), + DualAxisProcessor::from_iter([DualAxisInverted::ALL.into()]), DualAxisProcessor::Pipeline(vec![Arc::new(DualAxisInverted::ALL.into())]) ); assert_eq!( - DualAxisProcessor::from(vec![ + DualAxisProcessor::from_iter([ DualAxisInverted::ALL.into(), DualAxisSensitivity::all(2.0).into(), ]), diff --git a/src/input_processing/mod.rs b/src/input_processing/mod.rs index 6c4e666a..cb92fdc6 100644 --- a/src/input_processing/mod.rs +++ b/src/input_processing/mod.rs @@ -26,8 +26,8 @@ //! //! You can also use these methods to create a pipeline. //! -//! - [`AxisProcessor::with_processor`] or [`From>::from`] for [`AxisProcessor::Pipeline`]. -//! - [`DualAxisProcessor::with_processor`] or [`From>::from`] for [`DualAxisProcessor::Pipeline`]. +//! - [`AxisProcessor::with_processor`] or [`FromIterator::from_iter`] for [`AxisProcessor::Pipeline`]. +//! - [`DualAxisProcessor::with_processor`] or [`FromIterator::from_iter`] for [`DualAxisProcessor::Pipeline`]. //! //! ## Inversion //! diff --git a/src/input_processing/single_axis/mod.rs b/src/input_processing/single_axis/mod.rs index 79ef51b8..de109164 100644 --- a/src/input_processing/single_axis/mod.rs +++ b/src/input_processing/single_axis/mod.rs @@ -79,7 +79,7 @@ pub enum AxisProcessor { /// /// assert_eq!( /// expected, - /// AxisProcessor::from(vec![ + /// AxisProcessor::from_iter([ /// AxisProcessor::Inverted, /// AxisProcessor::Sensitivity(2.0), /// ]) @@ -141,9 +141,9 @@ impl AxisProcessor { } } -impl From> for AxisProcessor { - fn from(value: Vec) -> Self { - Self::Pipeline(value.into_iter().map(Arc::new).collect()) +impl FromIterator for AxisProcessor { + fn from_iter>(iter: T) -> Self { + Self::Pipeline(iter.into_iter().map(Arc::new).collect()) } } @@ -208,19 +208,19 @@ mod tests { } #[test] - fn test_axis_processor_from_list() { - assert_eq!(AxisProcessor::from(vec![]), AxisProcessor::Pipeline(vec![])); + fn test_axis_processor_from_iter() { + assert_eq!( + AxisProcessor::from_iter([]), + AxisProcessor::Pipeline(vec![]) + ); assert_eq!( - AxisProcessor::from(vec![AxisProcessor::Inverted]), + AxisProcessor::from_iter([AxisProcessor::Inverted]), AxisProcessor::Pipeline(vec![Arc::new(AxisProcessor::Inverted)]), ); assert_eq!( - AxisProcessor::from(vec![ - AxisProcessor::Inverted, - AxisProcessor::Sensitivity(2.0), - ]), + AxisProcessor::from_iter([AxisProcessor::Inverted, AxisProcessor::Sensitivity(2.0)]), AxisProcessor::Pipeline(vec![ Arc::new(AxisProcessor::Inverted), Arc::new(AxisProcessor::Sensitivity(2.0)),