diff --git a/src/card/tests.rs b/src/card/tests.rs index b1ddbbb..e310f3c 100644 --- a/src/card/tests.rs +++ b/src/card/tests.rs @@ -268,7 +268,7 @@ mod test_impls { use crate::{ card::{Card, PlayingCard, Rank, Suit}, - helper::ExactSizedArr, + exactsizearr::ExactSizedArr, }; #[test] diff --git a/src/exactsizearr.rs b/src/exactsizearr.rs new file mode 100644 index 0000000..e9891f3 --- /dev/null +++ b/src/exactsizearr.rs @@ -0,0 +1,23 @@ +/// An iterator adaptor (derived from ExactSizedIterator) which has a guaranteed +/// compile time size, allowing for collection of an iterator into a stack +/// allocated array. +pub trait ExactSizedArr: ExactSizeIterator + Sized +where + I: Default, +{ + fn into_array(mut self) -> Result<[Self::Item; N], Self> { + if self.len() < N { + Err(self) + } else { + Ok(std::array::from_fn(|_| self.next().unwrap())) + } + } +} + +/// Default implementation of ExactSizedArr for any ExactSizeIterator. +impl ExactSizedArr for I +where + T: Default + Copy + Clone, + I: ExactSizeIterator, +{ +} diff --git a/src/helper.rs b/src/helper.rs index 817a530..858a7f0 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -5,30 +5,6 @@ pub fn ordered(mut xs: [T; N]) -> [T; N] { xs } -/// An iterator adaptor (derived from ExactSizedIterator) which has a guaranteed -/// compile time size, allowing for collection of an iterator into a stack -/// allocated array. -pub trait ExactSizedArr: ExactSizeIterator + Sized -where - I: Default, -{ - fn into_array(mut self) -> Result<[Self::Item; N], Self> { - if self.len() < N { - Err(self) - } else { - Ok(std::array::from_fn(|_| self.next().unwrap())) - } - } -} - -/// Default implementation of ExactSizedArr for any ExactSizeIterator. -impl ExactSizedArr for I -where - T: Default + Copy + Clone, - I: ExactSizeIterator, -{ -} - /// A macro which generates Eq, PartialEq, and PartialOrd implementations for /// some given type. These implementations are dependent on Ord already being /// implemented for that type. diff --git a/src/main.rs b/src/main.rs index 4bb6bb1..bba6ed0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ #![cfg_attr(not(clippy), allow(dead_code))] mod card; +mod exactsizearr; mod helper; mod modes;