#[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.

Note that at the moment, we can only derive fieldless enums and the return value is always None.

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

Example

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