Migrate from near_sdk::collections to near_sdk::store#37
Conversation
mfornet
left a comment
There was a problem hiding this comment.
It is unfortunate the introduction of new clones. Mostly because I expect, inside these methods, the object is fully serialized, so it is first cloned, then serialized. This is feedback we can pass on to the near-sdk-rs team.
sept-en
left a comment
There was a problem hiding this comment.
LGTM! Looks cleaner now. The only thing is to perhaps wait for API to stabilize, as we want to have a minimal impact on future upgrades.
|
I've created #38 for changing internal function signature to get rid of some of the new clones. I should have more insights afterwards and will leave another comment then. We're using So I assume it's fine to merge this PR now. @sept-en wdyt? |
|
@mooori makes sense to me. This PR is ok to merge for sure. |
This only affects the Acl plugin, other plugins aren't using
near_sdk::collections.Motivation
near_sdk::collectionswill be put under the legacy feature flag and its successor isnear_sdk::store. Once a contract uses a plugin based oncollections, it will require efforts to migrate that contract to a new plugin version based onstore. To avoid that, let's migratenear-pluginsitself tonear_sdk::storebefore any plugins are used in production.near_sdk::storeMain differences to
near_sdk::collectionsare described in the last section of this post.Feature flag
unstableTo use
storeit's currently still required to enable theunstablefeature fornear_sdk. Seems likestorewill be stabilized in sdk version 4.1 (currently it's at 4.0.0).Implementation details
Usage patterns are more idiomatic for rust
For instance maps now have
get_mutwhich allows removing patterns likeget element -> modify it -> write back to map.Clones
Using
storewithout changing any function signatures requires cloning values at various places since somenear-sdkfunctions previously handling references now handle owned values and vice versa. For instancecollections::UnorderedSet::inserthas parameterelement: &Twhilestore::UnorderedSet::inserthas parameterelement: T.A follow-up PR could change some signatures of internal functions of the Acl plugin to avoid some of these clones.
Review
It might be more convenient to look at the commits individually.