pub struct CppBox<T: CppDeletable> { /* private fields */ }
Expand description
A C++ pointer wrapper to manage deletion of objects.
Objects of CppBox should be created by calling into_box() for types that implement CppDeletable trait. The object will be deleted when corresponding CppBox is deleted.
Implementations
sourceimpl<T: CppDeletable> CppBox<T>
impl<T: CppDeletable> CppBox<T>
sourcepub fn as_mut_ptr(&self) -> *mut T
pub fn as_mut_ptr(&self) -> *mut T
Returns mutable raw pointer to the value in the box.
sourceimpl<T: CppDeletable> CppBox<T>
impl<T: CppDeletable> CppBox<T>
sourcepub unsafe fn new(ptr: *mut T) -> CppBox<T>
pub unsafe fn new(ptr: *mut T) -> CppBox<T>
Encapsulates the object into a CppBox.
You should use this function only for
pointers that were created on C++ side and passed through
a FFI boundary to Rust. An object created with C++ new
must be deleted using C++ delete
, which is executed by CppBox
.
Do not use this function for objects created in memory managed by Rust. Any wrapper constructor or function that returns an owned object is supposed to be deleted using Rust’s ownage system and Drop trait.
Do not use this function for objects that would be deleted by other means.
If another C++ object is the owner of the passed object,
it will attempt to delete it. If CppBox
containing the object still exists,
it would result in a double deletion, which should never happen.
Use CppBox::into_raw
to unwrap the pointer before passing it to
a function that takes ownership of the object.
It’s permitted to put a null pointer into a CppBox
. Deleter function
will not be called for a null pointer. However, attempting to dereference
a null pointer in a CppBox
using as_ref
, as_mut
, deref
or deref_mut
will result in a panic.