Trait DecodeError

Source
pub trait DecodeError<E> {
    // Required method
    fn type_of() -> &'static str;

    // Provided method
    fn decode_custom_error_to_enum(custom: u32) -> Option<E>
       where E: FromPrimitive { ... }
}
👎Deprecated since 2.3.0: Use num_traits::FromPrimitive instead
Expand description

Allows custom errors to be decoded back to their original enum.

Some Solana error enums, like ProgramError, include a Custom variant, like ProgramError::Custom, that contains a u32 error code. This code may represent any error that is not covered by the error enum’s named variants. It is common for programs to convert their own error enums to an error code and store it in the Custom variant, possibly with the help of the ToPrimitive trait.

This trait builds on the FromPrimitive trait to help convert those error codes to the original error enum they represent.

As this allows freely converting u32 to any type that implements FromPrimitive, it is only used correctly when the caller is certain of the original error type.

Required Methods§

Source

fn type_of() -> &'static str

👎Deprecated since 2.3.0: Use num_traits::FromPrimitive instead

Provided Methods§

Source

fn decode_custom_error_to_enum(custom: u32) -> Option<E>
where E: FromPrimitive,

👎Deprecated since 2.3.0: Use num_traits::FromPrimitive instead

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§