-
Notifications
You must be signed in to change notification settings - Fork 5
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(sails): Storage trait, impls, examples #767
Draft
vobradovich
wants to merge
8
commits into
master
Choose a base branch
from
vo/storage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
efa4a68
wip: Storage for RefMut
vobradovich fcab519
wip: StorageAccessor & SyncUnsafeCell
vobradovich 6c926d3
replace static lifetime with 'a
vobradovich f6a18c3
Merge branch 'master' into vo/storage
vobradovich bb67cf7
add static_storage macros, tests
vobradovich 61a6560
Merge branch 'master' into vo/storage
vobradovich dbf069c
Merge branch 'master' into vo/storage
vobradovich 098283d
wip: static_storage experiments
vobradovich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use sails_rs::{prelude::*, static_storage}; | ||
|
||
#[derive(Default)] | ||
pub struct Data(pub u128); | ||
static_storage!(Data, Data(0u128)); | ||
|
||
pub struct Service<'a> { | ||
storage: Box<dyn Storage<Item = Data> + 'a>, | ||
} | ||
|
||
impl<'a> Service<'a> { | ||
pub fn new(storage: impl Storage<Item = Data> + 'a) -> Self { | ||
Self { | ||
storage: Box::new(storage), | ||
} | ||
} | ||
|
||
pub fn from_accessor<T: StorageAccessor<'a, Data>>(accessor: &'a T) -> Self { | ||
Self { | ||
storage: accessor.boxed(), | ||
} | ||
} | ||
} | ||
|
||
#[service(events = Event)] | ||
impl Service<'_> { | ||
pub fn bump(&mut self) { | ||
let state = self.storage.get_mut(); | ||
state.0 = state.0.saturating_add(1); | ||
|
||
self.notify_on(Event::Bumped).expect("unable to emit event"); | ||
} | ||
|
||
pub fn get(&self) -> u128 { | ||
self.storage.get().0 | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Encode, TypeInfo)] | ||
#[codec(crate = sails_rs::scale_codec)] | ||
#[scale_info(crate = sails_rs::scale_info)] | ||
enum Event { | ||
Bumped, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it in gstd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or it's like everything to be used in programs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, all the stuff for the program under
gstd