Skip to content

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.

@vobradovich vobradovich added the rust Pull requests that update Rust code label Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants