Derive Macro concordium_std::Reject

source ·
#[derive(Reject)]
{
    // Attributes available to this derive:
    #[from]
}
Expand description

Derive the conversion of enums that represent error types into the Reject struct which can be used as the error type of init and receive functions. Creating custom enums for error types can provide meaningful error messages to the user of the smart contract.

When a contract function rejects, the enum is serialized and returned along with the error code. The serialization means that the enum must implement Serial if Reject is to be derived.

The conversion will map the first variant to error code -1, second to -2, etc.

Example

#[derive(Reject, Serial)]
enum MyError {
    IllegalState, // receives error code -1
    WrongSender, // receives error code -2
    TimeExpired(time: Timestamp), // receives error code -3
    ...
}
#[receive(contract = "my_contract", name = "some_receive")]
fn receive<A: HasActions>(ctx: &impl HasReceiveContext, state: &mut MyState)
-> Result<A, MyError> {...}