pub struct ParseError {}
Expand description

Zero-sized type to represent an error when reading bytes and deserializing.

When using custom error types in your smart contract, it is convenient to implement the trait From<ParseError> for you custom error type, to allow using the ? operator when deserializing bytes, such as the contract state or parameters.

enum MyCustomReceiveError {
    Parsing
}

impl From<ParseError> for MyCustomReceiveError {
    fn from(_: ParseError) -> Self { MyCustomReceiveError::Parsing }
}

#[receive(contract = "mycontract", name="some_receive_name", mutable)]
fn contract_receive<S: HasStateApi>(
    ctx: &impl HasReceiveContext,
    host: &mut impl HasHost<State, StateApiType = S>,
) -> Result<A, MyCustomReceiveError> {
    // ...
    let msg: MyParameterType = ctx.parameter_cursor().get()?;
    // ...
}

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Mapped to i32::MIN + 2.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.