pub struct RawExceptionRef<'s> { /* private fields */ }Expand description
A raw exception borrowed from an abort buffer, [CXS(selector)][payload].
In the SDK this only exists inside the on_exn dispatch closure of
try_call_raw_with, borrowing the call scratch for exactly the closure’s
lifetime; RawException is its owned form. On the host, the mock
executor parses one straight from a frame’s abort buffer.
Copy: all three fields are, and MatchExn hands out reborrows of it.
Covariance in 's makes a copy usable at any shorter lifetime.
Implementations§
Source§impl<'s> RawExceptionRef<'s>
impl<'s> RawExceptionRef<'s>
Sourcepub fn parse(wire: &'s [u8]) -> Result<RawExceptionRef<'s>, ReadError>
pub fn parse(wire: &'s [u8]) -> Result<RawExceptionRef<'s>, ReadError>
Fails only when the buffer does not start with a CXS-encoded u64:
the frame aborted with something other than a contract exception.
pub fn selector(&self) -> u64
pub fn payload(&self) -> &'s [u8] ⓘ
Sourcepub fn payload_start(&self) -> usize
pub fn payload_start(&self) -> usize
Sourcepub fn to_owned<O>(self) -> Owhere
O: From<RawExceptionRef<'s>>,
pub fn to_owned<O>(self) -> Owhere
O: From<RawExceptionRef<'s>>,
Detach into an owned exception (one copy). Which owned type is up to
the caller’s context; the SDK’s RawException is the one that
exists, and this resolves through its From impl.
Sourcepub fn try_as<T>(&self) -> Option<T>where
T: Exn + ReadXDROwned,
pub fn try_as<T>(&self) -> Option<T>where
T: Exn + ReadXDROwned,
Decode as T if the selector matches, None otherwise.
None covers two different situations, a selector belonging to some
other type, and this type’s selector over a payload that will not
decode. Use try_decode when they need telling
apart.
T must contain no auth-token handle (the SDK’s Signed): abort
frames carry none, so one would decode to the uninitialized
u32::MAX sentinel, a value shaped like an auth token that faults on
use. Nothing is checked here; spec canonicalization rejects such a
payload when the contract is built.
Sourcepub fn try_decode<T>(&self) -> Option<Result<T, ReadError>>where
T: Exn + ReadXDROwned,
pub fn try_decode<T>(&self) -> Option<Result<T, ReadError>>where
T: Exn + ReadXDROwned,
try_as with the decode failure kept separate from
the selector mismatch:
None: the selector belongs to some other exception type.Some(Ok(t)): the selector matched and the payload decoded.Some(Err(e)): the selector matched, but the payload does not decode asT.
The third case is not only a forged or truncated payload. An
exception’s selector is sha256(major_version :: crate :: type) and
says nothing about the payload’s layout, so a callee that adds an
enum variant (a semver-compatible change that leaves the selector
untouched) throws something an older caller cannot decode. Since
try_as reports that as None, indistinguishable from an
unrelated error type, a caller that must not confuse the two should
reach for this instead.
Note that decoding reads a prefix: a payload carrying extra
trailing bytes decodes as the shorter shape and is reported as
Some(Ok(..)). Appending a field is therefore accepted silently
rather than surfacing here.
Trait Implementations§
Source§impl<'s> Clone for RawExceptionRef<'s>
impl<'s> Clone for RawExceptionRef<'s>
Source§fn clone(&self) -> RawExceptionRef<'s>
fn clone(&self) -> RawExceptionRef<'s>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'s> Copy for RawExceptionRef<'s>
Source§impl Debug for RawExceptionRef<'_>
impl Debug for RawExceptionRef<'_>
Source§impl From<RawExceptionRef<'_>> for RawException
What RawExceptionRef::to_owned produces: one copy. Any number may
be live at once; without alloc each value carries its own fixed
SCRATCH_MAX-capacity buffer.
impl From<RawExceptionRef<'_>> for RawException
What RawExceptionRef::to_owned produces: one copy. Any number may
be live at once; without alloc each value carries its own fixed
SCRATCH_MAX-capacity buffer.
Source§fn from(exn: RawExceptionRef<'_>) -> Self
fn from(exn: RawExceptionRef<'_>) -> Self
Source§impl MatchExn for RawExceptionRef<'_>
impl MatchExn for RawExceptionRef<'_>
Source§fn as_exn(&self) -> Option<RawExceptionRef<'_>>
fn as_exn(&self) -> Option<RawExceptionRef<'_>>
None if this failure carries none (a
fault, an invalid call, an encode/decode failure).Source§fn try_as<E: Exn + ReadXDROwned>(&self) -> Option<E>
fn try_as<E: Exn + ReadXDROwned>(&self) -> Option<E>
E if this failure carries an exception of that type. Read moreSource§fn try_decode<E: Exn + ReadXDROwned>(&self) -> Option<Result<E, ReadError>>
fn try_decode<E: Exn + ReadXDROwned>(&self) -> Option<Result<E, ReadError>>
Source§impl ReThrow for RawExceptionRef<'_>
Re-throw to our caller: abort with the original wire bytes, verbatim.
No additional guest buffer; the return syscall still copies bytes to the
host. This is what plain (non-try_) generated methods do.
impl ReThrow for RawExceptionRef<'_>
Re-throw to our caller: abort with the original wire bytes, verbatim.
No additional guest buffer; the return syscall still copies bytes to the
host. This is what plain (non-try_) generated methods do.