Migrate from near_sdk::collections
to near_sdk::store
#37
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 only affects the Acl plugin, other plugins aren't using
near_sdk::collections
.Motivation
near_sdk::collections
will 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-plugins
itself tonear_sdk::store
before any plugins are used in production.near_sdk::store
Main differences to
near_sdk::collections
are described in the last section of this post.Feature flag
unstable
To use
store
it's currently still required to enable theunstable
feature fornear_sdk
. Seems likestore
will 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_mut
which allows removing patterns likeget element -> modify it -> write back to map
.Clones
Using
store
without changing any function signatures requires cloning values at various places since somenear-sdk
functions previously handling references now handle owned values and vice versa. For instancecollections::UnorderedSet::insert
has parameterelement: &T
whilestore::UnorderedSet::insert
has 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.