Take storage keys as reference (K -> &K) #265
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change encourages the use of ownes types as
PrimaryKey
, which makes it very easy to deserialize bytes into owned keys. This can be implemented forAddr
.Since you cannot deserialize borrowed bytes into an owned object, a copy is created in
parse_key
. However,parse_key
is never used.In order to avoid copying around owned keys when thes are needed in multiple locations, the key arguments of all the storage functions were turned into references.
This is basically how the type system of standard library maps like https://doc.rust-lang.org/std/collections/struct.HashMap.html works: You have an owned key type
K
that is used plain in a few places. But get takes a reference. InHashMap
theK
can be of unknown size (e.g.[u8]
). This is something we cannot do as long as we want to keepparse_key
, which deserializes into an ownedK
.Do not merge as is. Target branch is a copy of the fork from #260.