feat(sails): Storage trait, impls, examples#767
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.
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.
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)
);| pub mod calls; | ||
| pub mod events; | ||
| pub mod services; | ||
| pub mod storage; |
There was a problem hiding this comment.
or it's like everything to be used in programs?
There was a problem hiding this comment.
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.
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.
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.