pub trait IntoPreallocatedFFIValue: RIType {
    type SelfInstance;

    // Required method
    fn into_preallocated_ffi_value(
        self_instance: Self::SelfInstance,
        context: &mut dyn FunctionContext,
        allocated: Self::FFIType
    ) -> Result<()>;
}
Expand description

Something that can be converted into a preallocated ffi value.

Every type parameter that should be given as &mut into a runtime interface function, needs to implement this trait. After executing the host implementation of the runtime interface function, the value is copied into the preallocated wasm memory.

This should only be used for types which have a fixed size, like slices. Other types like a vec do not work with this interface, as we can not call into wasm to reallocate memory. So, this trait should be implemented carefully.

Required Associated Types§

source

type SelfInstance

As Self can be an unsized type, it needs to be represented by a sized type at the host. This SelfInstance is the sized type.

Required Methods§

source

fn into_preallocated_ffi_value( self_instance: Self::SelfInstance, context: &mut dyn FunctionContext, allocated: Self::FFIType ) -> Result<()>

Convert self_instance into the given preallocated ffi value.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl IntoPreallocatedFFIValue for [u8]

§

type SelfInstance = Vec<u8>

source§

fn into_preallocated_ffi_value( self_instance: Self::SelfInstance, context: &mut dyn FunctionContext, allocated: u64 ) -> Result<()>

source§

impl<const N: usize> IntoPreallocatedFFIValue for [u8; N]

§

type SelfInstance = [u8; N]

source§

fn into_preallocated_ffi_value( self_instance: Self::SelfInstance, context: &mut dyn FunctionContext, allocated: u32 ) -> Result<()>

Implementors§