pub unsafe trait LuaAllocator {
// Required methods
unsafe fn allocate(&self, layout: Layout) -> Option<NonNull<u8>>;
unsafe fn reallocate(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Option<NonNull<u8>>;
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout);
}Expand description
Allocates memory for a Luau state.
The VM passes exact Rust layouts for every allocation. Implementations must return pointers that satisfy the requested layout and must deallocate or reallocate pointers using the corresponding previous layout. Reallocation to an equal or smaller size must not fail.
§Safety
Returned pointers must be valid for reads and writes of layout.size()
bytes, aligned to layout.align(), and remain allocated until passed back
to reallocate or deallocate. reallocate must preserve the first
old_layout.size().min(new_layout.size()) bytes on success, and must
return Some when new_layout.size() <= old_layout.size().
Required Methods§
unsafe fn allocate(&self, layout: Layout) -> Option<NonNull<u8>>
unsafe fn reallocate( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Option<NonNull<u8>>
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".