#[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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.