pub trait MapExceptions {
type Mapped<F>;
// Required method
fn map_exceptions<X, F>(&self, on_exn: F) -> Self::Mapped<F>
where F: for<'s> FnOnce(RawExceptionRef<'s>) -> X;
}Expand description
Classify a borrowed exception during a generated call.
Generated clients implement this trait. Use
client.map_exceptions(classify).try_method(...) to return a compact
exception value instead of an owned RawException.
The adapter preserves the client’s address, gas limit and invocation flags,
and is consumed by one call. Only a parsed exception invokes the mapper;
success, faults, rejected calls and encode/decode errors keep their usual
RawCallError representation.
The mapper borrows abort bytes already copied from the host into guest
scratch; its return value cannot borrow them. This avoids an additional
owned exception buffer, not the host/guest copies.
Prefer a compact classification or verbatim rethrow. Taking an owned copy
is allowed, but in RV32 contracts with alloc that allocation is not
reclaimed during the invocation. Decoding types with owned fields can
also allocate.
The call scratch stays checked out during the mapper. Do other SDK work
or throw a new typed error after the mapped call returns, when its scratch
checkout has ended. Without alloc, this does not guarantee that
the compiler reuses its stack slot; test the release RV32 artifact.
Import this trait (included in use thruput_sdk::*) for method syntax.
If a contract has its own map_exceptions method, use
MapExceptions::map_exceptions(&client, classify) instead.
Required Associated Types§
Required Methods§
Sourcefn map_exceptions<X, F>(&self, on_exn: F) -> Self::Mapped<F>where
F: for<'s> FnOnce(RawExceptionRef<'s>) -> X,
fn map_exceptions<X, F>(&self, on_exn: F) -> Self::Mapped<F>where
F: for<'s> FnOnce(RawExceptionRef<'s>) -> X,
Map a borrowed exception during the next generated try_* call.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".