pub struct OpaqueHandle<T: ?Sized> { /* private fields */ }Expand description
Wrapper around a Box<T> that knows how to round-trip through a
raw *mut c_void pointer without exposing unsafe at call sites.
See the module docs for the safety contract.
Implementations§
Source§impl<T> OpaqueHandle<T>
impl<T> OpaqueHandle<T>
Sourcepub fn new(value: T) -> *mut c_void
pub fn new(value: T) -> *mut c_void
Box value and return it as an opaque raw pointer. The caller
owns the allocation; pass it to from_raw to
reclaim it.
Sourcepub unsafe fn from_raw(ptr: *mut c_void)
pub unsafe fn from_raw(ptr: *mut c_void)
Reclaim a pointer produced by new (or
into_raw) and drop the underlying value.
Calling this on a NULL pointer is a no-op. Calling it twice on
the same non-NULL pointer is undefined behavior.
§Safety
ptr must either be NULL or have been produced by
OpaqueHandle::new / OpaqueHandle::into_raw for the same
type T, and must not have been reclaimed already.
Source§impl<T: ?Sized> OpaqueHandle<T>
impl<T: ?Sized> OpaqueHandle<T>
Sourcepub unsafe fn borrow_raw<'a>(ptr: *mut c_void) -> &'a mut Twhere
T: Sized,
pub unsafe fn borrow_raw<'a>(ptr: *mut c_void) -> &'a mut Twhere
T: Sized,
Borrow the live state behind ptr for the duration of the
returned reference. The pointer is not reclaimed — the
allocation remains owned by whoever holds it (typically the
Confium loader, until destroy is called).
The returned &mut T borrow is tied to the lifetime 'a so
callers cannot accidentally outlive it through Copy/Clone.
§Safety
ptr must be a non-NULL pointer produced by
OpaqueHandle::new / OpaqueHandle::into_raw for a type
that is layout-compatible with T, and must remain valid for
the duration of 'a. The v0 plugin contract guarantees this:
instance handles are single-threaded and live until destroy.