pub struct Userdata { /* private fields */ }Implementations§
Source§impl Userdata
impl Userdata
Sourcepub const unsafe fn from_raw(raw: NonNull<RawUserdata>) -> Self
pub const unsafe fn from_raw(raw: NonNull<RawUserdata>) -> Self
Constructs a non-owning handle from a VM userdata record.
§Safety
raw must address a live RawUserdata owned by the VM in which this
handle will be used. The handle does not root the userdata or extend
its lifetime.
pub fn allocation_size_for_payload_len(payload_len: usize) -> Option<usize>
Sourcepub unsafe fn metatable(&self) -> Option<Table>
pub unsafe fn metatable(&self) -> Option<Table>
Returns this userdata’s metatable handle, if present.
§Safety
The userdata and its owning VM must be live. The returned handle is non-owning and is invalidated when the metatable is freed.
Sourcepub unsafe fn set_metatable(&self, metatable: Option<Table>)
pub unsafe fn set_metatable(&self, metatable: Option<Table>)
Replaces this userdata’s metatable pointer.
§Safety
The userdata must be live, and metatable, when present, must belong
to the same VM. The caller must maintain the VM’s GC barrier protocol.
pub fn total_payload_len(&self) -> usize
pub const fn data_ptr(&self) -> *const u8
Sourcepub const unsafe fn data_mut_ptr(&self) -> *mut u8
pub const unsafe fn data_mut_ptr(&self) -> *mut u8
Returns the mutable address of this userdata’s inline payload.
§Safety
The userdata must be live, and the caller must enforce bounds and aliasing for every access through the returned pointer.
Sourcepub unsafe fn set_inline_destructor(
&self,
requested_payload_len: usize,
destructor: LuaInlineDestructor,
)
pub unsafe fn set_inline_destructor( &self, requested_payload_len: usize, destructor: LuaInlineDestructor, )
Stores the inline destructor following the requested payload.
§Safety
This must be an inline-destructor userdata whose allocation contains a
destructor-sized trailer immediately after requested_payload_len.
Sourcepub unsafe fn inline_destructor(&self) -> LuaInlineDestructor
pub unsafe fn inline_destructor(&self) -> LuaInlineDestructor
Loads the destructor stored after an inline-destructor payload.
§Safety
This must be a live inline-destructor userdata whose payload trailer
was initialized with a valid LuaInlineDestructor.
Sourcepub unsafe fn allocation_size(&self) -> usize
pub unsafe fn allocation_size(&self) -> usize
Returns this userdata allocation’s full GC size.
§Safety
The userdata record must be live and its stored payload length must describe the allocation that contains it.