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(sails): Storage trait, impls, examples #767

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

Conversation

vobradovich
Copy link
Member

No description provided.

@vobradovich vobradovich self-assigned this Jan 10, 2025
macro_rules! static_storage {
($type:ty, $init:expr) => {
impl $type {
pub(crate) fn storage() -> impl Storage<Item = $type> + 'static {
Copy link
Member

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

Copy link
Member Author

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;
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member Author

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;
Copy link
Member

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)

Copy link
Member Author

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.

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.

2 participants