Skip to main content

component_storage

Attribute Macro component_storage 

Source
#[component_storage]
Expand description

Wires storage metadata for an account component’s storage struct.

Apply this to the struct that declares the component’s #[storage(...)] fields. It generates the Default implementation and implements the account traits so the component’s methods can access storage and account operations. Use it together with a #[component] trait (the API) and a #[component] trait implementation (the behavior).

use miden::{StorageValue, Word, component, component_storage};

#[component_storage]
struct MyComponentStorage {
    #[storage(description = "some field")]
    foo: StorageValue<Word>,
}

#[component]
trait MyComponent {
    fn get_foo(&self) -> Word;
}

#[component]
impl MyComponent for MyComponentStorage {
    fn get_foo(&self) -> Word {
        self.foo.get()
    }
}