#[repr(C)]
pub struct ResultAbi<T> { /* private fields */ }
Expand description

This is an encoding of a Result. It can only store things that can be decoded by the JS bindings.

At the moment, we do not write the exact struct packing layout of everything into the glue/descriptions of datatypes, so T cannot be arbitrary. The current requirements of the struct unpacker (StructUnpacker), which apply to ResultAbi as a whole, are as follows:

  • repr(C), of course
  • u32/i32/f32/f64 fields at the “leaf fields” of the “field tree”
  • layout equivalent to a completely flattened repr(C) struct, constructed by an in order traversal of all the leaf fields in it.

This means that you can’t embed struct A(u32, f64) as struct B(u32, A); because the “completely flattened” struct AB(u32, u32, f64) would miss the 4 byte padding that is actually present within B and then as a consequence also miss the 4 byte padding within A that repr(C) inserts.

The enemy is padding. Padding is only required when there is an f64 field. So the enemy is f64 after anything else, particularly anything arbitrary. There is no smaller sized type, so we don’t need to worry about 1-byte integers, etc. It’s best, therefore, to place your f64s first in your structs, that’s why we have abi first, although here it doesn’t matter as the other two fields total 8 bytes anyway.

Trait Implementations§

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for ResultAbi<T>where
    T: RefUnwindSafe,

§

impl<T> Send for ResultAbi<T>where
    T: Send,

§

impl<T> Sync for ResultAbi<T>where
    T: Sync,

§

impl<T> Unpin for ResultAbi<T>where
    T: Unpin,

§

impl<T> UnwindSafe for ResultAbi<T>where
    T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.