[][src]Function holochain_wasmer_guest::host_call

pub fn host_call<'a, I: 'a, O>(
    f: unsafe extern "C" fn(_: GuestPtr) -> Len,
    payload: &'a I
) -> Result<O, WasmError> where
    SerializedBytes: TryFrom<&'a I, Error = SerializedBytesError>,
    O: TryFrom<SerializedBytes, Error = SerializedBytesError>, 

Given an extern that we expect the host to provide, that takes a GuestPtr and returns a Len:

  • Serialize the payload by reference, according to its SerializedBytes implementation
  • Write the bytes into a new allocation
  • Call the host function and pass it the pointer to our allocation full of serialized data
  • Deallocate the serialized bytes when the host function completes
  • Allocate empty bytes of the length that the host tells us the result is
  • Ask the host to write the result into the allocated empty bytes
  • Deserialize and deallocate whatever bytes the host has written into the result allocation
  • Return a Result of the deserialized output type O