Expand description
Utilities for transferring heap-allocated Rust Vec<T>
values across an FFI boundary.
The primary abstraction offered by this module is CVec
, a C-compatible struct that stores
a raw pointer (ptr
) together with the vector’s logical len
and cap
. By moving the
allocation metadata into a plain repr(C)
type we allow the memory created by Rust to be
owned, inspected, and ultimately freed by foreign code (or vice-versa) without introducing
undefined behaviour.
Only a very small API surface is exposed to C:
cvec_new
– create an empty vector representation.cvec_drop
– free a vector that was obtained from Rust.
All other manipulation happens on the Rust side before relinquishing ownership. This keeps the
rules for memory safety straightforward: foreign callers must treat the memory region pointed
to by ptr
as opaque and interact with it solely through the functions provided here.
Structs§
- CVec
CVec
is a C compatible struct that stores an opaque pointer to a block of memory, it’s length and the capacity of the vector it was allocated from.