Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IntoIterator for &Vec<> #1328

Merged
merged 3 commits into from
Sep 10, 2024
Merged

Add IntoIterator for &Vec<> #1328

merged 3 commits into from
Sep 10, 2024

Conversation

leighmcculloch
Copy link
Member

@leighmcculloch leighmcculloch commented Sep 9, 2024

What

Add IntoIterator for &Vec<>.

Why

To improve the ergonomics of using the soroban_sdk::Vec type.

So that it is possible to do for _ in &vec. So it is possible to iterate a vec without moving it.

Today if a developer would like to iterate a Vec without moving it, they need to write for _ in vec.iter(). This pattern is a little odd because ordinarily a developer just passes &vec to iterate without moving.

Note that iterating &vec will still be somewhat different than it would be to iterate a ref of a std::vec::Vec from the Rust std library. This is because the Rust std library Vec when iterating a vec is iterating refs to items in the vec. When iterating a soroban_sdk::Vec there is no items in memory to ref, rather during iteration each item is communicated across the host-guest interface and must be passed by value as no one is holding onto its value.

@leighmcculloch leighmcculloch marked this pull request as ready for review September 9, 2024 06:29
@leighmcculloch
Copy link
Member Author

Tests will pass once this issue merges:

@leighmcculloch leighmcculloch requested a review from a team September 10, 2024 06:46
@leighmcculloch leighmcculloch added this pull request to the merge queue Sep 10, 2024
Merged via the queue into main with commit 5b2558e Sep 10, 2024
16 checks passed
@leighmcculloch leighmcculloch deleted the vec-intoiter-ref branch September 10, 2024 21:03
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.

2 participants