Skip to content

Conversation

@kirillsemyonkin
Copy link
Collaborator

@kirillsemyonkin kirillsemyonkin commented Mar 7, 2025

This PR is a variant of implementing IntoIterator via an &'a reference to the respective collections (IArray, IMap).

This means the iterator may not outlive the instance. For example, you may not return the iterator from a function, if the supplied IArray does not outlive the function scope:

fn first<'a>(arr: &'a IArray<i32>) -> impl Iterator<Item = i32> + 'a { // note that implemented object lives as long as that reference - it borrows `arr`
    arr.into_iter() // ok in any solution
}

fn second() -> impl Iterator<Item = i32> {
    let arr = IArray::...;
    arr.into_iter() // cannot happen, as `IArray` will be `Drop`ped at the end of this scope
}

The IArray implementation is rewritten to the same approach for consistency. Breaking change.

Closes #69 because the two approaches are disjoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant