Expand description
Marshalling helpers that bridge Rust values and the C ABI’s (ptr, len)
slots.
These functions are the audited home of the pointer operations a WeaveFFI
producer performs on strings, bytes, and value buffers. The
#[weaveffi::module] expansion wires the generated thunks to them:
- lift functions read a borrowed
(ptr, len)parameter. They never take ownership of caller memory; the borrowing variants (lift_str,lift_byte_slice) don’t even copy. - lower functions hand an owned value to the consumer as a
producer-allocated
(ptr, len)run, which the consumer releases with{prefix}_free_bytes(seefree_bytes). allocis the body of{prefix}_alloc: a run the consumer fills and either frees with{prefix}_free_bytesor hands to the producer (a callback’s string, bytes, or buffer return), which adopts it withadopt_bytes. Every run is aBox<[u8]>allocation, so one release function covers both directions.
Strings, bytes, and serialized value buffers all share this one
representation: a string is its UTF-8 bytes, never NUL-terminated, so an
interior NUL round-trips intact. A null pointer is valid only with a
length of 0 and denotes the empty run.
Functions§
- adopt_
bytes ⚠ - Adopt a run from
alloc(or one this runtime returned) as an owned vector. Null with a length of0is the empty run; null with any other length yieldsNone. - alloc
- The body of
{prefix}_alloc: allocate a zero-filled run oflenbytes the consumer fills, released withfree_bytes(the samelen) or handed to the producer, which adopts it. Alenof0returns null, which is the empty run. - bytes_
into_ raw - Turn an owned byte vector into the producer-allocated
(ptr, len)run a return slot or async result carries, to be released withfree_bytes. An empty vector yields(null, 0)and allocates nothing. - free_
bytes ⚠ - The body of
{prefix}_free_bytes: release a run returned by this runtime (a string, bytes, or a value buffer) or allocated withalloc. A nullptror alenof0is a no-op. - lift_
byte_ ⚠slice - Borrow a
(ptr, len)parameter as a byte slice for a caller-chosen lifetime, without copying. - lift_
bytes ⚠ - Copy a
(ptr, len)parameter into an ownedVec<u8>. - lift_
str ⚠ - Borrow a
(ptr, len)string parameter as a&str, validating UTF-8, without copying. - lift_
string ⚠ - Copy a
(ptr, len)string parameter into an ownedString, validating UTF-8. - lower_
bytes ⚠ - Lower an owned byte vector into a return value plus the trailing
size_t* out_lenslot. Seebytes_into_raw. - lower_
string ⚠ - Lower an owned string as its UTF-8 bytes, exactly like
lower_bytes.