forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the StorableSlice trait to the std library (FuelLabs#4302)
## Description This PR introduces a way more generalized way to store heap types into storage as discussed [here](FuelLabs#4013) with the `StorableSlice` trait. The current implementation of the `store` and `get` functions do not support heap types. With the use of `raw_slice` any heap types may now be stored. This PR unlocks FuelLabs/sway-libs#40 which is required for a number of other issues. With the introduction of the `StorableSlice` trait, the `StorageBytes` have been refactored to use it. This trait could be used to convert a `Vec` to a `StorageVec` in an efficient manner in another PR. While `Vec` already has the ability to convert to a `raw_slice`, `Storage_Vec` stores each element using a unique key created by hashing the index of that element i.e. sha256(index) in a more linked-list like fashion. This would need to be changed if this functionality is desired. **NOTE:** A `from_raw_slice` function has been added to the `Bytes` type to enable the refactor. This should be removed and replaced once FuelLabs#3882 is resolved and also uses the `len_bytes` function introduced in that PR. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: bitzoic <[email protected]>
- Loading branch information
Showing
5 changed files
with
290 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.