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

feat: add mutable methods to the storage Vec type #6250

Open
enitrat opened this issue Aug 20, 2024 · 3 comments
Open

feat: add mutable methods to the storage Vec type #6250

enitrat opened this issue Aug 20, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@enitrat
Copy link
Contributor

enitrat commented Aug 20, 2024

Feature Request

Describe the Feature Request

The Vec type is for now an append-only data structure. We can only append at the end, and retrieve existing values.

We could also add:

  • set
  • delete / unset (reset value at index i to default value)
  • pop

I can help if needed.

@enitrat enitrat added the enhancement New feature or request label Aug 20, 2024
@enitrat
Copy link
Contributor Author

enitrat commented Aug 21, 2024

Proposal: also improve the API so that one can do

self.storage_vec.at(i) instead of self.storage_vec.at(i).read()
self.storage_vec.append(x) instead of self.storage_vec.append().write(x)

@orizi
Copy link
Collaborator

orizi commented Aug 21, 2024

this is a breaking change - additionally - it merges the concepts of finding a Vec cell, and the actual edit of one, which makes it much less explicit.

@enitrat
Copy link
Contributor Author

enitrat commented Aug 21, 2024

append is quite misleading in this case, it's connoted as mutating a data structure.

Perhaps something like this would be better:

self.storage_vec.last_mut()-> returns the storage path to the last storage cell of the vec, so that we can do
self.storage_vec.last_mut().write(x) (or self.storage_vec.last_mut().read()).

And thus, the features I would like to see could be expressed as

self.storage_vec.get_mut(i).write(x) self.storage_vec.get_mut(i).delete()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants