Skip to content

Commit

Permalink
create 3 explicit impls for IntoIterator for snapshot-collections
Browse files Browse the repository at this point in the history
  • Loading branch information
cairoIover committed Jan 7, 2025
1 parent 7b3c22b commit 09d696f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
7 changes: 0 additions & 7 deletions corelib/src/array.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -816,13 +816,6 @@ impl SpanIntoIterator<T> of crate::iter::IntoIterator<Span<T>> {
}
}

impl SnapshotSpanIntoIterator<T> of crate::iter::IntoIterator<@Span<T>> {
type IntoIter = crate::array::SpanIter<T>;
fn into_iter(self: @Span<T>) -> Self::IntoIter {
(*self).into_iter()
}
}

/// An iterator struct over an array collection.
#[derive(Drop)]
pub struct ArrayIter<T> {
Expand Down
23 changes: 19 additions & 4 deletions corelib/src/iter/traits/collect.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,25 @@ impl IteratorIntoIterator<T, +Iterator<T>> of IntoIterator<T> {
}
}

impl SnapshotIteratorSpanBased<C, T, +Into<@C, Span<T>>> of IntoIterator<@C> {
impl SnapshotFixedSizeArrayIntoIterator<
T, const SIZE: usize, +Drop<T>, impl ToSpan: core::array::ToSpanTrait<[T; SIZE], T>,
> of IntoIterator<@[T; SIZE]> {
type IntoIter = crate::array::SpanIter<T>;
fn into_iter(self: @C) -> Self::IntoIter {
let span: Span<T> = self.into();
span.into_iter()
fn into_iter(self: @[T; SIZE]) -> Self::IntoIter {
ToSpan::span(self).into_iter()
}
}

impl SnapshotSpanIntoIterator<T> of IntoIterator<@Span<T>> {
type IntoIter = crate::array::SpanIter<T>;
fn into_iter(self: @Span<T>) -> Self::IntoIter {
(*self).into_iter()
}
}

impl SnapshotArrayIntoIterator<T> of IntoIterator<@Array<T>> {
type IntoIter = crate::array::SpanIter<T>;
fn into_iter(self: @Array<T>) -> Self::IntoIter {
self.span().into_iter()
}
}

0 comments on commit 09d696f

Please sign in to comment.