Struct cpp_utils::CppBox

source ·
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

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.

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

Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Returns the “default value” for a type. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.