-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description When creating complex storage types, storing of a `StorageKey` is sometimes needed. In these cases a `new()` function is appropriate. For example, when we have the following storage block: ```rust storage { name: StorageMap<u64, StorageKey<StorageString>> = StorageMap {}, } ``` In order to store a `StorageString` in a `StorageMap`, the `StorageKey<StorageString>` annotation is needed. From there, we can store a `String` by creating a `StorageKey`, storing a `String` at said key, and then storing the `StorageKey` in the `StorageMap`: ```rust let string_key: StorageKey<StorageString> = StorageKey { slot: sha256(0), offset: 0, field_id: sha256(1), }; string_key.write_slice(String::from_ascii_str("my_name")); storage.name.insert(0, string_key); ``` The introduction of `new()` would change this to the following: ```rust let string_key: StorageKey<StorageString> = StorageKey::new( sha256(0), 0, sha256(1) ); string_key.write_slice(String::from_ascii_str("my_name")); storage.name.insert(0, string_key); ``` ## 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). - [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
4 changed files
with
60 additions
and
21 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