pub trait Boxed: Sized {
// Required methods
unsafe fn from_raw(ptr: *mut c_void) -> Self;
fn into_raw(self) -> *mut c_void;
fn as_raw(&self) -> *const c_void;
fn as_raw_mut(&mut self) -> *mut c_void;
}
Expand description
Trait for structures that are created on the C++ side, usually only the raw void pointer is stored to point to the allocated data on the heap.
Required Methods§
sourceunsafe fn from_raw(ptr: *mut c_void) -> Self
unsafe fn from_raw(ptr: *mut c_void) -> Self
Wrap the specified raw pointer
§Safety
Caller must ensure that the passed pointer is pointing to a valid unowned object data
sourcefn into_raw(self) -> *mut c_void
fn into_raw(self) -> *mut c_void
Return the underlying raw pointer while consuming this wrapper.
This will not free object referenced by this pointer, so you can use this pointer indefinitely. Be sure
to free it (by e.g. calling from_raw()
with the same wrapper type) to avoid leaking memory.
sourcefn as_raw(&self) -> *const c_void
fn as_raw(&self) -> *const c_void
Return the underlying raw pointer.
You can use this pointer as long as the original object lives. Be careful not to double-free it.
sourcefn as_raw_mut(&mut self) -> *mut c_void
fn as_raw_mut(&mut self) -> *mut c_void
Return the underlying mutable raw pointer
You can use this pointer as long as the original object lives. Be careful not to double-free it. Note
that ownership is still retained in the original object. Use into_raw()
if you want to transfer
ownership to another wrapper.