Type Definition concordium_std::InitResult

source ·
pub type InitResult<S> = Result<S, Reject>;
Expand description

The expected return type of the init method of the smart contract, parametrized by the state type of the smart contract.

Optionally, to define a custom type for error instead of using Reject, allowing the track the reason for rejection, but only in unit tests.

See also the documentation for bail! for how to use custom error types.

Example

Defining a custom error type that implements Reject and Serial.

#[derive(Serial, Reject)]
enum MyCustomError {
    SomeError,
}

#[init(contract = "mycontract")]
fn contract_init<S: HasStateApi>(
    _ctx: &impl HasInitContext,
    _state_builder: &mut StateBuilder<S>,
) -> Result<(), MyCustomError> {
    Err(MyCustomError::SomeError)
}