Skip to main content

OpaqueHandle

Struct OpaqueHandle 

Source
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>

Source

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.

Source

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

pub fn into_raw(value: T) -> *mut c_void

Take ownership of value, box it, and yield the raw pointer. Equivalent to new but reads better when you already have a value to hand off.

Source§

impl<T: ?Sized> OpaqueHandle<T>

Source

pub unsafe fn borrow_raw<'a>(ptr: *mut c_void) -> &'a mut T
where 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.

Auto Trait Implementations§

§

impl<T> Freeze for OpaqueHandle<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for OpaqueHandle<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for OpaqueHandle<T>
where T: Send + ?Sized,

§

impl<T> Sync for OpaqueHandle<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for OpaqueHandle<T>
where T: Unpin + ?Sized,

§

impl<T> UnsafeUnpin for OpaqueHandle<T>
where T: ?Sized,

§

impl<T> UnwindSafe for OpaqueHandle<T>
where T: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.