Struct cpp_utils::CppBox
[−]
[src]
pub struct CppBox<T: CppDeletable> { /* fields omitted */ }
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.
Methods
impl<T: CppDeletable> CppBox<T>
[src]
fn as_ptr(&self) -> *const T
Returns constant raw pointer to the value in the box.
fn as_mut_ptr(&self) -> *mut T
Returns mutable raw pointer to the value in the box.
fn into_raw(self) -> *mut T
Returns the pointer that was used to create the object and destroys the box. The caller of the function becomes the owner of the object and should ensure that the object will be deleted at some point.
fn is_null(&self) -> bool
Returns true if the pointer is null.
impl<T: CppDeletable> CppBox<T>
[src]
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.
Trait Implementations
impl<T: CppDeletable> AsRef<T> for CppBox<T>
[src]
fn as_ref(&self) -> &T
Performs the conversion.
impl<T: CppDeletable> AsMut<T> for CppBox<T>
[src]
fn as_mut(&mut self) -> &mut T
Performs the conversion.
impl<T: CppDeletable> Deref for CppBox<T>
[src]
type Target = T
The resulting type after dereferencing
fn deref(&self) -> &T
The method called to dereference a value
impl<T: CppDeletable> DerefMut for CppBox<T>
[src]
fn deref_mut(&mut self) -> &mut T
The method called to mutably dereference a value