Derive Macro sov_modules_api::ModuleInfo
source · #[derive(ModuleInfo)]
{
// Attributes available to this derive:
#[state]
#[module]
#[address]
}
Expand description
Derives the ModuleInfo
trait for the underlying struct
.
The underlying type must respect the following conditions, or compilation will fail:
- It must be a named
struct
. Tuplestruct
s,enum
s, and others are not supported. - It must have exactly one field with the
#[address]
attribute. This field represents the module address. - All other fields must have either the
#[state]
or#[module]
attribute.#[state]
is used for state members.#[module]
is used for module members.
In addition to implementing ModuleInfo
, this macro will
also generate so-called “prefix” methods.
Example
use sov_modules_api::{Context, ModuleInfo};
use sov_state::StateMap;
#[derive(ModuleInfo)]
struct TestModule<C: Context> {
#[address]
admin: C::Address,
#[state]
pub state_map: StateMap<String, u32>,
}
// You can then get the prefix of `state_map` like this:
fn get_prefix<C: Context>(some_storage: C::Storage) {
let test_struct = TestModule::<C>::default();
let prefix1 = test_struct.state_map.prefix();
}