pub struct CppUniquePtrPin<T: UniquePtrTarget>(/* private fields */);
Expand description
Any newtype wrapper which causes the contained UniquePtr
target to obey C++ reference
semantics rather than Rust reference semantics. That is, multiple aliasing
mutable C++ references may exist to the contents.
C++ references are permitted to alias one another, and commonly do. Rust references must alias according only to the narrow rules of the borrow checker.
Implementations§
Source§impl<T: UniquePtrTarget> CppUniquePtrPin<T>
impl<T: UniquePtrTarget> CppUniquePtrPin<T>
Methods from Deref<Target = CppMutRef<T>>§
Sourcepub fn as_mut_ptr(&self) -> *mut T
pub fn as_mut_ptr(&self) -> *mut T
Retrieve the underlying C++ pointer.
Methods from Deref<Target = CppRef<T>>§
Sourcepub unsafe fn as_ref(&self) -> &T
pub unsafe fn as_ref(&self) -> &T
Get a regular Rust reference out of this C++ reference.
§Safety
Callers must guarantee that the referent is not modified by any other C++ or Rust code while the returned reference exists. Callers must also guarantee that no mutable Rust reference is created to the referent while the returned reference exists.
Callers must also be sure that the C++ reference is properly aligned, not null, pointing to valid data, etc.
Sourcepub fn const_cast(&self) -> CppMutRef<T>
pub fn const_cast(&self) -> CppMutRef<T>
Create a mutable version of this reference, roughly equivalent
to C++ const_cast
.
The opposite is to use AsCppRef::as_cpp_ref
on a CppMutRef
to obtain a CppRef
.
§Safety
Because we never dereference a CppRef
in Rust, this cannot create
undefined behavior within Rust and is therefore not unsafe. It is
however generally unwise, just as it is in C++. Use sparingly.