pub struct AllocatedMemory<'g> { /* private fields */ }Expand description
AllocatedMemory itself is needed when allocating memory on the Rust side;
It is an RAII wrapper over memory allocated on the heap of the zygote
clone via Scope::alloc; Automatically sends a Free request
when going out of scope (Drop).
Important: Library has its own methods for working with memory -
they are also needed, but only when we are not the creators of the memory region.
To work with raw addresses allocated by the C side (for example, strdup),
use the Library methods directly.
'g is the lifetime of the ScopeGuard block of crate::ffi! in which it was created.
Until it is 'static — the value physically cannot be returned from crate::ffi! outside.
Implementations§
Source§impl<'g> AllocatedMemory<'g>
impl<'g> AllocatedMemory<'g>
Sourcepub fn read(&self) -> Result<Vec<u8>, FFIError>
pub fn read(&self) -> Result<Vec<u8>, FFIError>
Reads the entire allocated memory block from the zygote as raw bytes.
Sourcepub fn write(&self, value: impl FfiArg) -> Result<(), FFIError>
pub fn write(&self, value: impl FfiArg) -> Result<(), FFIError>
Writes a value into the allocated memory block in the zygote.
Sourcepub fn readStruct<T: Pod + Zeroable>(&self) -> Result<T, FFIError>
pub fn readStruct<T: Pod + Zeroable>(&self) -> Result<T, FFIError>
Reads the allocated memory as a statically-typed C struct T.
T must be #[repr(C)] and implement Pod (plain old data) from bytemuck.
The Pod bound is checked at compile time — if T has padding or non-POD fields,
the code will simply refuse to compile instead of silently reading garbage.
This eliminates all manual byte parsing: the struct’s size and field layout are guaranteed correct by the type system rather than by manually calculated offsets.