Derive Macro State

Source
#[derive(State)]
{
    // Attributes available to this derive:
    #[borrow]
}
Expand description

Derive macro for individual struct field type extractable through StateRef and StateOwn

ยงExample:


// use derive macro and attribute to mark the field that can be extracted.
#[derive(State, Clone)]
struct MyState {
    #[borrow]
    field: u128
}

// construct App with MyState type.
App::new()
    .with_state(MyState { field: 996 })
    .at("/", handler_service(index))

// extract u128 typed field from MyState.
async fn index(StateRef(num): StateRef<'_, u128>) -> String {
    assert_eq!(*num, 996);
    num.to_string()
}