pub struct ForeignCallback<V: Vtable> { /* private fields */ }Expand description
A consumer-implemented callback interface held by the producer.
Holds the consumer’s ctx and a pointer to its static vtable V. The
generated impl Trait for ForeignX calls
vtable().method(ctx, ...) per method; dropping the
last owner calls free(ctx).
Implementations§
Source§impl<V: Vtable> ForeignCallback<V>
impl<V: Vtable> ForeignCallback<V>
Sourcepub unsafe fn from_raw(
ctx: *mut c_void,
vtable: *const V,
) -> Result<Option<Self>, VtableTooSmall>
pub unsafe fn from_raw( ctx: *mut c_void, vtable: *const V, ) -> Result<Option<Self>, VtableTooSmall>
Adopt a (ctx, vtable) pair lifted from a callback-interface
parameter’s slots. Returns Ok(None) when the vtable pointer is null.
§Errors
Returns VtableTooSmall when the vtable’s size is smaller than
V. The context is released through the header’s free first (when
the header itself is complete), so a rejected callback doesn’t leak.
§Safety
vtable must be null or point to a vtable whose header is
initialized and whose first size bytes stay valid and unmodified
for the life of the returned value (consumers use a process-wide
static). ctx must remain valid until the vtable’s free entry is
called with it.