#[stateful]Expand description
Inject app states into the annotated function.
§Arguments
§init
A list of argument names to initialize to their default values
if they are not already initialized. This requires
the specified states to implement Default.
§Examples
§Injecting multiple states
use app_state::{AppState, MutAppState, stateful};
struct SomeState;
struct SomeMutState;
struct SomeOtherState;
#[stateful]
fn foo(app_state: AppState<SomeState>,
mut_app_state: MutAppState<SomeMutState>,
mut other_state: MutAppStateLock<SomeOtherState>) {
// ...
}
fn main() {
AppState::init(SomeState);
MutAppState::init(SomeMutState);
MutAppState::init(SomeOtherState);
foo();
}§Injecting states with default values
use app_state::{AppState, MutAppState, stateful};
#[derive(Default)]
struct SomeState;
#[derive(Default)]
struct SomeMutState;
#[derive(Default)]
struct SomeOtherState;
#[stateful(init(app_state, mut_app_state, other_state))]
fn foo(app_state: AppState<SomeState>,
mut_app_state: MutAppState<SomeMutState>,
mut other_state: MutAppStateLock<SomeOtherState>) {
// ...
}
fn main() {
// All states will be initialized with their default values
// if they are not already initialized.
foo();
}