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

Enable storing of a Vec with the StorageVec type #5123

Merged
merged 11 commits into from
Sep 26, 2023
Merged

Conversation

bitzoic
Copy link
Member

@bitzoic bitzoic commented Sep 18, 2023

Description

Currently, StorageVec and Vec do not have any relation with one another. This PR takes advantage of the recent optimization and refactoring done to the Storage API read() and write() functions in #4795 and enables the storing of a Vec using the StorageVec type.

To do this, the StorageVec now stores things sequentially rather than a different key for every element. Due to the optimizations done to the Storage API, this has become feasible as we can now load a single element of the sequential StorageVec.

The storing of elements sequentially mimics the existing Vec, allowing us to store it as a raw_slice with a single read/write to storage as opposed to looping over the Vec and having n read/writes.

It should be noted that due to #409, the storing of a Vec is written in the StorageVec file. This is the resulting syntax:

let my_vec = Vec::new();
storage.storage_vec.store_vec(my_vec); // Store the Vec
let other_vec = storage.storage_vec.load_vec(); // Read the Vec

When this issue is resolved, this should be changed to a From implementation changing the syntax to:

let my_vec = Vec::new();
storage.storage_vec = my_vec.into(); // Store the Vec
let other_vec = Vec::from(storage.storage_vec); // Read the Vec

Closes #2439

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@bitzoic bitzoic requested a review from a team September 18, 2023 11:42
@bitzoic bitzoic self-assigned this Sep 18, 2023
@bitzoic bitzoic added enhancement New feature or request lib: std Standard library labels Sep 18, 2023
K1-R1
K1-R1 previously approved these changes Sep 18, 2023
Copy link
Contributor

@K1-R1 K1-R1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

sway-lib-std/src/storage/storage_vec.sw Outdated Show resolved Hide resolved
sway-lib-std/src/storage/storage_vec.sw Show resolved Hide resolved
@IGI-111 IGI-111 requested a review from a team September 18, 2023 12:27
sway-lib-std/src/storage/storage_vec.sw Show resolved Hide resolved
sway-lib-std/src/storage/storage_vec.sw Outdated Show resolved Hide resolved
sway-lib-std/src/storage/storage_vec.sw Outdated Show resolved Hide resolved
@bitzoic bitzoic requested review from SwayStar123 and a team September 19, 2023 13:58
SwayStar123
SwayStar123 previously approved these changes Sep 19, 2023
@bitzoic bitzoic requested a review from a team September 21, 2023 07:49
@IGI-111 IGI-111 added the breaking May cause existing user code to break. Requires a minor or major release. label Sep 26, 2023
IGI-111
IGI-111 previously approved these changes Sep 26, 2023
@bitzoic bitzoic enabled auto-merge (squash) September 26, 2023 08:09
@bitzoic bitzoic dismissed stale reviews from SwayStar123 and IGI-111 via 5fa1d6a September 26, 2023 09:50
@bitzoic bitzoic requested a review from a team September 26, 2023 10:28
@bitzoic bitzoic merged commit 5392f8b into master Sep 26, 2023
32 checks passed
@bitzoic bitzoic deleted the bitzoic-vec-storage branch September 26, 2023 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking May cause existing user code to break. Requires a minor or major release. enhancement New feature or request lib: std Standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cast Vec to StorageVec
4 participants