Skip to main content

RawExceptionRef

Struct RawExceptionRef 

Source
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>

Source

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.

Source

pub fn selector(&self) -> u64

Source

pub fn wire(&self) -> &'s [u8] ⓘ

The full abort wire bytes, selector prefix included.

Source

pub fn payload(&self) -> &'s [u8] ⓘ

Source

pub fn payload_start(&self) -> usize

Where payload starts within wire.

Source

pub fn to_owned<O>(self) -> O
where 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.

Source

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.

Source

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 as T.

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>

Source§

fn clone(&self) -> RawExceptionRef<'s>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'s> Copy for RawExceptionRef<'s>

Source§

impl Debug for RawExceptionRef<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
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.

Source§

fn from(exn: RawExceptionRef<'_>) -> Self

Converts to this type from the input type.
Source§

impl MatchExn for RawExceptionRef<'_>

Source§

fn as_exn(&self) -> Option<RawExceptionRef<'_>>

The caught exception, or 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>

Decode as E if this failure carries an exception of that type. Read more
Source§

fn try_decode<E: Exn + ReadXDROwned>(&self) -> Option<Result<E, ReadError>>

try_as with the decode failure kept separate: Read more
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.

Source§

fn re_throw(self) -> !

Re-throw this error. Exceptions are propagated as exceptions; faults panic (a fault stays a fault).

Auto Trait Implementations§

§

impl<'s> Freeze for RawExceptionRef<'s>

§

impl<'s> RefUnwindSafe for RawExceptionRef<'s>

§

impl<'s> Send for RawExceptionRef<'s>

§

impl<'s> Sync for RawExceptionRef<'s>

§

impl<'s> Unpin for RawExceptionRef<'s>

§

impl<'s> UnsafeUnpin for RawExceptionRef<'s>

§

impl<'s> UnwindSafe for RawExceptionRef<'s>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> StaticIfNoAlloc for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.