Skip to main content

Module memory

Module memory 

Source
Expand description

§memory — FFI-safe heap buffers and strings

Provides FfiBuffer and FfiString: the two heap-allocated primitive types that cross the Go↔Rust boundary.

§Ownership model

  Rust allocates → caller (Go) reads → Rust frees
  • Rust is always the allocator. Go never allocates these types directly.
  • The Go side must call the matching ffi_*_free exported function when it is done with a value. Rust’s allocator is invoked; Go’s GC is not involved.
  • FfiBuffer and FfiString are repr(C) structs of raw pointers + sizes. They have no Drop impl — they cannot be safely dropped by Rust without explicit deallocation, which is intentional: the Go side controls lifetime.

Structs§

FfiBuffer
FFI-safe byte buffer with explicit ownership semantics.
FfiString
FFI-safe UTF-8 string.

Functions§

ffi_buffer_alloc
Allocate an FfiBuffer of capacity bytes.
ffi_buffer_free
Free an FfiBuffer previously allocated by this crate.
ffi_string_alloc
Allocate and copy a UTF-8 string of len bytes starting at str.
ffi_string_free
Free an FfiString previously allocated by this crate.