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]

Returns constant raw pointer to the value in the box.

Returns mutable raw pointer to the value in the box.

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.

Returns true if the pointer is null.

impl<T: CppDeletable> CppBox<T>
[src]

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]

Performs the conversion.

impl<T: CppDeletable> AsMut<T> for CppBox<T>
[src]

Performs the conversion.

impl<T: CppDeletable> Deref for CppBox<T>
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<T: CppDeletable> DerefMut for CppBox<T>
[src]

The method called to mutably dereference a value

impl<T: CppDeletable> Drop for CppBox<T>
[src]

A method called when the value goes out of scope. Read more

impl<T: CppDeletable> Default for CppBox<T>
[src]

Returns the "default value" for a type. Read more