pub struct CppMutRef<T: ?Sized>(/* private fields */);Expand description
A C++ non-const reference. These are different from Rust’s &mut T in that
several C++ references can exist to the same underlying data (“aliasing”)
and that’s not permitted for regular Rust references.
See CppRef for details on safety, usage models and implementation.
You can convert this to a CppRef using the std::convert::Into trait.
Implementations§
Source§impl<T: ?Sized> CppMutRef<T>
impl<T: ?Sized> CppMutRef<T>
Sourcepub fn as_mut_ptr(&self) -> *mut T
pub fn as_mut_ptr(&self) -> *mut T
Retrieve the underlying C++ pointer.
Sourcepub unsafe fn as_mut(&mut self) -> &mut T
pub unsafe fn as_mut(&mut self) -> &mut T
Get a regular Rust mutable 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 other 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.
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.