pub struct Table<T: 'static> { /* private fields */ }Expand description
A C table that starts with uint32_t size: Anvil’s host table or a
service’s. Its provider may be older than this crate, so its table may be
shorter than T. Table keeps the pointer and the provider’s size and
never makes a &T that reaches past them: the crate reads a field only
when size covers it (the ANVIL_*_HAS macros of the C headers), and
get hands out &T only for a table at least as long as T.
Implementations§
Source§impl<T> Table<T>
impl<T> Table<T>
Sourcepub unsafe fn from_raw(ptr: *const T) -> Option<Self>
pub unsafe fn from_raw(ptr: *const T) -> Option<Self>
The table behind ptr; None for null. Only its first four bytes,
the size, are read here.
§Safety
ptr is null or points to a table of T’s layout (or an older,
shorter version of it) whose first field is u32 size, with at least
size bytes readable, unchanged and valid for the process; T is
plain data without interior mutability (a C table of size, values
and function pointers), so that sharing it between threads is sound.
Sourcepub fn get(&self) -> Option<&'static T>
pub fn get(&self) -> Option<&'static T>
The whole table as T, when the provider’s is at least as long as
T; None from an older provider, whose table is shorter.