Trait PointerWrapper
pub unsafe trait PointerWrapper<N>: Sized {
// Required methods
fn wrap(ptr: *mut N) -> Option<Self>;
fn unwrap(self) -> *mut N;
fn inner(&self) -> &N;
fn inner_mut(&mut self) -> &mut N;
}Expand description
This trait supports the conversion of a wrapper into it’s wrapped C/C++ pointer and back.
The wrapped value can be accessed through the functions inner and inner_mut.
§Safety
The native value N should be treated as opaque, because its definition may change
without adhering to semantic versioning and depends on what the tool bindgen is able to generate.
Converting from a Rust wrapper to the wrapped value loses the automatic ability to free associated resources.
Required Methods§
fn wrap(ptr: *mut N) -> Option<Self>
fn wrap(ptr: *mut N) -> Option<Self>
Wraps a native pointer into a wrapper type.
Returns None if the pointer is null.
fn inner_mut(&mut self) -> &mut N
fn inner_mut(&mut self) -> &mut N
Access the wrapped pointer.
Some native types store pointers into their own memory, and C++ writes through them.
Calling C++ functions that modify such a type through the returned reference is undefined
behavior in Rust, because a &mut N promises that nothing else writes to the object while
the reference exists. For these calls, use PointerWrapper::unwrap and
PointerWrapper::wrap to work with the raw pointer instead.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".