Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(collections): Lazy storage value #409

Merged
merged 6 commits into from
May 18, 2021
Merged

feat(collections): Lazy storage value #409

merged 6 commits into from
May 18, 2021

Conversation

austinabell
Copy link
Contributor

As mentioned in #406 this implements the lazy storage type, which is similar to LazyOption except that the assertion that the value exists in storage is maintained by the API to allow easier usage for developers.

This PR re-uses the cache entry type from #402 (with small adjustments) to solidify that API and ensure it can be used for other types. Also for simplicity, this brings in the once_cell crate for lazily filling the cache cell under the feature flag, but only specific logic needed can be ported over to minimize compiled size if necessary.

@austinabell austinabell changed the title feat: Lazy storage value feat(collections): Lazy storage value May 10, 2021
@austinabell
Copy link
Contributor Author

per our discussions, I will be moving this type to the new module. The name is still not specified, so either storage or store, does anyone have opinions?

@@ -29,6 +29,9 @@ near-primitives-core = "=0.4.0"
# Export dependencies for contracts
wee_alloc = { version = "0.4.5", default-features = false, features = [] }

# Used for caching, might be worth porting only functionality needed.
once_cell = { version = "1.7.2", optional = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
once_cell = { version = "1.7.2", optional = true }
once_cell = { version = "1.7.2", optional = true, default-features = false }

I think need only no_std (single threaded ) version.

@matklad
Copy link
Contributor

matklad commented May 12, 2021

store feels better to me -- shorter, and it has a "a specific thing" connotation, which is good -- store refers to a specific global store.

@@ -0,0 +1,91 @@
use borsh::{BorshDeserialize, BorshSerialize};

use super::Lazy;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

me this weekend.

/// This will only write to the underlying store if the value has changed, and will only read the
/// existing value from storage once.
///
/// # Examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again appreciate these doc examples

@mikedotexe mikedotexe merged commit 91beb67 into master May 18, 2021
@mikedotexe mikedotexe deleted the austin/col/lazy branch May 18, 2021 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants