Skip to content

Commit

Permalink
feat(breaking): make FromIteratorFixed more generic (#21)
Browse files Browse the repository at this point in the history
Daniel-Aaron-Bloom authored Jun 16, 2024
1 parent ac2fa82 commit ab7c49d
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/from.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ use crate::IteratorFixed;
/// documentation for more examples.
///
/// See also: [`crate::IntoIteratorFixed`].
pub trait FromIteratorFixed<I: Iterator, const N: usize> {
pub trait FromIteratorFixed<T, const N: usize> {
/// Creates a value from a fixed size iterator.
///
/// Basic usage:
@@ -32,10 +32,10 @@ pub trait FromIteratorFixed<I: Iterator, const N: usize> {
/// let a: [i32; 3] = two_four_six.collect();
/// assert_eq!(a, [2, 4, 6]);
/// ```
fn from_iter_fixed(iter_fixed: IteratorFixed<I, N>) -> Self;
fn from_iter_fixed<I: Iterator<Item = T>>(iter_fixed: IteratorFixed<I, N>) -> Self;
}

impl<I: Iterator, const N: usize> FromIteratorFixed<I, N> for [<I as Iterator>::Item; N] {
impl<T, const N: usize> FromIteratorFixed<T, N> for [T; N] {
/// Creates an array from a fixed size iterator.
///
/// Basic usage:
@@ -57,7 +57,7 @@ impl<I: Iterator, const N: usize> FromIteratorFixed<I, N> for [<I as Iterator>::
/// let a: [i32; 3] = two_four_six.collect();
/// assert_eq!(a, [2, 4, 6]);
/// ```
fn from_iter_fixed(iter_fixed: IteratorFixed<I, N>) -> Self {
fn from_iter_fixed<I: Iterator<Item = T>>(iter_fixed: IteratorFixed<I, N>) -> Self {
let IteratorFixed { inner: mut it } = iter_fixed;
// We know that it will yield N elements due to it originating from an IteratorFixed
// of size N
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -230,7 +230,7 @@ where
/// let a: [i32; 3] = two_four_six.collect();
/// assert_eq!(a, [2, 4, 6]);
/// ```
pub fn collect<U: FromIteratorFixed<I, N>>(self) -> U {
pub fn collect<U: FromIteratorFixed<I::Item, N>>(self) -> U {
U::from_iter_fixed(self)
}
}

0 comments on commit ab7c49d

Please sign in to comment.