Skip to main content

Module marshal

Module marshal 

Source
Expand description

The glue every generated thunk calls: per-family parameter lifting, return lowering, and the synchronous call driver.

The #[weaveffi::module] expansion emits one short call per parameter and per return into this module instead of inlining the marshalling, so sync thunks, async launchers, iterator steps, and callback-interface wrappers share one implementation of each family’s rules:

  • lift_* functions turn a parameter’s C slots into the Rust value the producer’s function takes, or a MARSHAL_ERROR_CODE error naming the parameter. A thunk lifts every parameter before it looks at any result, so a callback context or the object tokens in a buffer are always adopted (and released again) even when another parameter fails.
  • lower_* functions (and CEnum::to_i32) turn a returned value into its C return and out slots.
  • call_sync runs a synchronous thunk’s body under catch_unwind and reports its outcome through out_err.

Traits§

CEnum
A C-style enum: an i32 discriminant at the C ABI and inside value buffers. The #[weaveffi::module] expansion implements it for every #[repr(i32)] #[weaveffi::enumeration].
Sentinel
The zero value a C return slot carries when a call fails: 0, false, 0.0, or null. Implemented for every C return type a thunk can have, () for void, and pairs and tuples of them (an async completion’s result slots).

Functions§

buffer_run
A value buffer as an async completion’s owned (result_ptr, result_len) run.
byte_slots
Borrow a bytes-like argument as the (ptr, len) slots of a callback method call.
bytes_run
Bytes as an async completion’s owned (result_ptr, result_len) run.
call_sync⚠
Run a synchronous thunk’s body and report its outcome: Ok clears out_err and returns the value; Err stores the error and returns the Sentinel; a panic is caught and reported with the panic code, so it never unwinds into C.
lift_buffer_param⚠
Decode a value-buffer parameter (a record, rich enum, optional, list, or map), adopting any object tokens it carries.
lift_bytes_param⚠
Copy a bytes parameter into an owned Vec<u8>.
lift_callback_opt_param⚠
Adopt an optional callback-interface parameter (Cb?); a null vtable is None.
lift_callback_param⚠
Adopt a callback-interface parameter’s (ctx, vtable) pair.
lift_enum
Lift a C-style enum parameter.
lift_object_arc_opt_param⚠
Retain an optional object parameter (I?); null is None.
lift_object_arc_param⚠
Take a new strong reference to an object parameter, so the producer can retain it.
lift_object_opt_param⚠
Borrow an optional object parameter (I?); null is None.
lift_object_param⚠
Borrow an object parameter for the call.
lift_self⚠
Lift a method’s receiver (self), borrowed for the call.
lift_self_arc⚠
Lift a method’s receiver as a retained reference (self: Arc<Self>, and every async method, whose future outlives the launcher).
lift_slice_param⚠
Borrow a bytes parameter’s (ptr, len) run as a slice.
lift_str_param⚠
Borrow a string parameter’s UTF-8 (ptr, len) run as a &str.
lift_string_param⚠
Copy a string parameter into an owned String.
lower_buffer_ret⚠
Encode a returned value buffer as a producer-allocated run plus *out_len.
lower_bytes_ret⚠
Lower returned bytes as a producer-allocated run plus *out_len.
lower_string_ret⚠
Lower a returned string as a producer-allocated run plus *out_len.
read_enum
Read a C-style enum from a value buffer (the body of its BufferValue::read_value).
str_slots
Borrow a string-like argument as the (ptr, len) slots of a callback method call.
string_run
A string as an async completion’s owned (result_ptr, result_len) run.
write_enum
Write a C-style enum into a value buffer (the body of its BufferValue::write_value).