-
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
base: master
Are you sure you want to change the base?
Conversation
macro_rules! static_storage { | ||
($type:ty, $init:expr) => { | ||
impl $type { | ||
pub(crate) fn storage() -> impl Storage<Item = $type> + 'static { |
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.
I'd create mod here maybe so if we declare multiple storages - they don't conflict in namespaces
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.
Instead of impl type
? This is a possible solution, but it would be better to have all storages generated in one place - module or type, like
static_storage!(service1::Data, service1::Data(0u128));
static_storage!(service2::Data, service2::Data(0u128));
generates
mod srorage {
...
}
or
static_storage!(
service1::Data => service1::Data(0u128),
service1::Data => service1::Data(0u128)
);
@@ -12,6 +12,7 @@ use core::cell::OnceCell; | |||
pub mod calls; | |||
pub mod events; | |||
pub mod services; | |||
pub mod storage; |
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
pub trait Storage { | ||
type Item; | ||
|
||
fn get(&self) -> &Self::Item; |
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.
what about providing also smth like with_data(FnOnce(&Self::Item) -> T) and with_data_mut(FnOnce(&mut Self::Item) -> T) as a reminder of need to free storage access (for cell, for example)
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.
it's not clear why. The storage should be read in the program at the moment when the service constructor is called (once per message). And it is dropped after.
That is why Storage
is implemented for RefMut
and not for RefCell
.
No description provided.