Take storage keys as reference (K -> &K)#265
Take storage keys as reference (K -> &K)#265webmaster128 wants to merge 1 commit intoupdate-cosmwasm-std-0.14.0-beta2from
Conversation
There was a problem hiding this comment.
This is nice in that it really "forces" the use of references on the user.
But, it's not different from the case in which you define the key as a reference.
In the original case, the & is flexible / optional, and can go inside the K, whereas in this case the & is fixed (outside the K). And, you can still put it inside of it (leading to double references).
I prefer the former version, for simplicity. Even when you could be using values by defining a value key, that can be easily fixed (by changing the key definition in one place). Plus, you have the freedom to do that if you need to, for whatever reason.
That said, both versions are OK with me. The fact of parse_key deserializing to an owned value is irrelevant / minor, in my opinion.
This is crucial. Before you had But what you can do is put This makes a few things a bit less fancy. But I think those get nicer over time when you migrate |
|
Agreed. But as you mentioned, Anyway, both options are OK with me. |
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_keyis 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
Kthat is used plain in a few places. But get takes a reference. InHashMaptheKcan 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.