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

Iter for StorageVec #6796

Open
bitzoic opened this issue Dec 19, 2024 · 1 comment · May be fixed by #6803
Open

Iter for StorageVec #6796

bitzoic opened this issue Dec 19, 2024 · 1 comment · May be fixed by #6803
Assignees
Labels
lib: std Standard library

Comments

@bitzoic
Copy link
Member

bitzoic commented Dec 19, 2024

An internal contributor has requested the Iter trait be implemented for StorageVec

@bitzoic bitzoic added the lib: std Standard library label Dec 19, 2024
@kostekIV
Copy link

Hi, wouldnt there be a problem with function purity? Iterator::next is pure but unless the StorageVec would be preloaded as VecIter the next would require some reads. Asking out of curiosity :)

So implementation that would look like this is not feasible unless there would be a new Iterator trait for Storage structs:

pub struct StorageVecIter<T> {
    storage_vec: StorageKey<StorageVec<T>>,
    vec_len: u64,
    index: u64,
}

impl<T> Iterator for StorageVecIter<T> {
    type Item = StorageKey<T>;

    fn next(ref mut self) -> Option<Self::Item> {
        if self.index >= vec_len {
            return None
        }

        self.index += 1;
        self.storage_vec.get(self.index - 1)
    }
}

@bitzoic bitzoic self-assigned this Jan 2, 2025
@bitzoic bitzoic linked a pull request Jan 2, 2025 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib: std Standard library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants