[][src]Struct cpp_core::MutRef

pub struct MutRef<T>(_);

A non-null, mutable pointer to a C++ object (similar to a C++ reference).

MutRef never owns its content.

Note that unlike Rust references, MutRef can be freely copied, producing multiple mutable pointers to the same object, which is usually necessary to do when working with C++ libraries.

MutRef implements operator traits and delegates them to the corresponding C++ operators. This means that you can use &ptr + value to access the object's operator+.

MutRef implements Deref and DerefMut, allowing to call the object's methods directly. In addition, methods of the object's first base class are also directly available thanks to nested Deref implementations.

If the object provides an iterator interface through begin() and end() functions, MutRef will implement IntoIterator, so you can iterate on it directly.

Safety

It's not possible to automatically track the ownership of objects possibly managed by C++ libraries. The user must ensure that the object is alive while MutRef exists. Note that with MutRef, it's possible to call unsafe C++ code without using any more unsafe Rust code, for example, by using operator traits, so care should be taken when exposing MutRef in a safe interface.

Methods

impl<T> MutRef<T>[src]

pub unsafe fn new(ptr: MutPtr<T>) -> Option<Self>[src]

Creates a MutRef from a MutPtr. Returns None if ptr is null.

Safety

ptr must be valid. See type level documentation.

pub unsafe fn from_raw(ptr: *mut T) -> Option<Self>[src]

Creates a MutRef from a raw pointer. Returns None if ptr is null.

Safety

ptr must be valid. See type level documentation.

pub unsafe fn from_raw_ref(value: &mut T) -> Self[src]

Creates a MutRef from a raw reference.

Safety

value must be alive as long as MutRef or pointers derived from it are used. See type level documentation.

pub unsafe fn from_raw_non_null(ptr: NonNull<T>) -> Self[src]

Creates a MutRef from a non-null pointer.

Safety

ptr must be valid. See type level documentation.

pub unsafe fn as_ptr(self) -> Ptr<T>[src]

Converts self to a Ptr.

Safety

self must be valid. See type level documentation.

pub unsafe fn as_mut_ptr(self) -> MutPtr<T>[src]

Converts self to a MutPtr.

Safety

self must be valid. See type level documentation.

pub fn as_raw_ptr(self) -> *const T[src]

Returns constant raw pointer to the value.

pub fn as_mut_raw_ptr(self) -> *mut T[src]

Returns mutable raw pointer to the value.

pub unsafe fn static_upcast<U>(self) -> Ref<U> where
    T: StaticUpcast<U>, 
[src]

Converts the pointer to the base class type U.

Safety

This operation is safe as long as self is valid.

pub unsafe fn static_downcast<U>(self) -> Ref<U> where
    T: StaticDowncast<U>, 
[src]

Converts the pointer to the derived class type U.

It's recommended to use dynamic_cast instead because it performs a checked conversion.

Safety

This operation is safe as long as self is valid and it's type is U or inherits from U.

pub unsafe fn dynamic_cast<U>(self) -> Option<Ref<U>> where
    T: DynamicCast<U>, 
[src]

Converts the pointer to the derived class type U. Returns None if the object's type is not U and doesn't inherit U.

Safety

This operation is safe as long as self is valid.

pub unsafe fn static_upcast_mut<U>(self) -> MutRef<U> where
    T: StaticUpcast<U>, 
[src]

Converts the pointer to the base class type U.

Safety

This operation is safe as long as self is valid.

pub unsafe fn static_downcast_mut<U>(self) -> MutRef<U> where
    T: StaticDowncast<U>, 
[src]

Converts the pointer to the derived class type U.

It's recommended to use dynamic_cast instead because it performs a checked conversion.

Safety

This operation is safe as long as self is valid and it's type is U or inherits from U.

pub unsafe fn dynamic_cast_mut<U>(self) -> Option<MutRef<U>> where
    T: DynamicCast<U>, 
[src]

Converts the pointer to the derived class type U. Returns None if the object's type is not U and doesn't inherit U.

Safety

This operation is safe as long as self is valid.

Trait Implementations

impl<T: 'static, U> Add<U> for MutRef<T> where
    &'static T: Add<U>, 
[src]

type Output = <&'static T as Add<U>>::Output

The resulting type after applying the + operator.

impl<T: 'static, U> AddAssign<U> for MutRef<T> where
    T: AddAssign<U>, 
[src]

impl<T: 'static, U> BitAnd<U> for MutRef<T> where
    &'static T: BitAnd<U>, 
[src]

type Output = <&'static T as BitAnd<U>>::Output

The resulting type after applying the & operator.

impl<T: 'static, U> BitAndAssign<U> for MutRef<T> where
    T: BitAndAssign<U>, 
[src]

impl<T: 'static, U> BitOr<U> for MutRef<T> where
    &'static T: BitOr<U>, 
[src]

type Output = <&'static T as BitOr<U>>::Output

The resulting type after applying the | operator.

impl<T: 'static, U> BitOrAssign<U> for MutRef<T> where
    T: BitOrAssign<U>, 
[src]

impl<T: 'static, U> BitXor<U> for MutRef<T> where
    &'static T: BitXor<U>, 
[src]

type Output = <&'static T as BitXor<U>>::Output

The resulting type after applying the ^ operator.

impl<T: 'static, U> BitXorAssign<U> for MutRef<T> where
    T: BitXorAssign<U>, 
[src]

impl<'a, T, U: CppDeletable> CastFrom<&'a mut CppBox<U>> for MutRef<T> where
    U: StaticUpcast<T>, 
[src]

impl<T, U> CastFrom<MutRef<U>> for MutPtr<T> where
    U: StaticUpcast<T>, 
[src]

impl<T, U> CastFrom<MutRef<U>> for Ref<T> where
    U: StaticUpcast<T>, 
[src]

impl<T, U> CastFrom<MutRef<U>> for Ptr<T> where
    U: StaticUpcast<T>, 
[src]

impl<T, U> CastFrom<MutRef<U>> for MutRef<T> where
    U: StaticUpcast<T>, 
[src]

impl<T> Clone for MutRef<T>[src]

Creates another pointer to the same object.

impl<T> Copy for MutRef<T>[src]

Creates another pointer to the same object.

impl<T> Debug for MutRef<T>[src]

impl<T> Deref for MutRef<T>[src]

Allows to call member functions of T and its base classes directly on the pointer.

type Target = T

The resulting type after dereferencing.

impl<T> DerefMut for MutRef<T>[src]

Allows to call member functions of T and its base classes directly on the pointer.

impl<T: 'static, U> Div<U> for MutRef<T> where
    &'static T: Div<U>, 
[src]

type Output = <&'static T as Div<U>>::Output

The resulting type after applying the / operator.

impl<T: 'static, U> DivAssign<U> for MutRef<T> where
    T: DivAssign<U>, 
[src]

impl<T, T1, T2> IntoIterator for MutRef<T> where
    T: BeginMut<Output = CppBox<T1>> + EndMut<Output = CppBox<T2>>,
    T1: CppDeletable + PartialEq<Ref<T2>> + Indirection + Increment,
    T2: CppDeletable
[src]

type Item = <T1 as Indirection>::Output

The type of the elements being iterated over.

type IntoIter = CppIterator<T1, T2>

Which kind of iterator are we turning this into?

impl<T: 'static, U> Mul<U> for MutRef<T> where
    &'static T: Mul<U>, 
[src]

type Output = <&'static T as Mul<U>>::Output

The resulting type after applying the * operator.

impl<T: 'static, U> MulAssign<U> for MutRef<T> where
    T: MulAssign<U>, 
[src]

impl<T, U> PartialEq<U> for MutRef<T> where
    T: PartialEq<U>, 
[src]

impl<T, U> PartialOrd<U> for MutRef<T> where
    T: Lt<U> + Le<U> + Gt<U> + Ge<U> + PartialEq<U>, 
[src]

impl<T: 'static, U> Rem<U> for MutRef<T> where
    &'static T: Rem<U>, 
[src]

type Output = <&'static T as Rem<U>>::Output

The resulting type after applying the % operator.

impl<T: 'static, U> RemAssign<U> for MutRef<T> where
    T: RemAssign<U>, 
[src]

impl<T: 'static, U> Shl<U> for MutRef<T> where
    &'static T: Shl<U>, 
[src]

type Output = <&'static T as Shl<U>>::Output

The resulting type after applying the << operator.

impl<T: 'static, U> ShlAssign<U> for MutRef<T> where
    T: ShlAssign<U>, 
[src]

impl<T: 'static, U> Shr<U> for MutRef<T> where
    &'static T: Shr<U>, 
[src]

type Output = <&'static T as Shr<U>>::Output

The resulting type after applying the >> operator.

impl<T: 'static, U> ShrAssign<U> for MutRef<T> where
    T: ShrAssign<U>, 
[src]

impl<T: 'static, U> Sub<U> for MutRef<T> where
    &'static T: Sub<U>, 
[src]

type Output = <&'static T as Sub<U>>::Output

The resulting type after applying the - operator.

impl<T: 'static, U> SubAssign<U> for MutRef<T> where
    T: SubAssign<U>, 
[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for MutRef<T> where
    T: RefUnwindSafe

impl<T> !Send for MutRef<T>

impl<T> !Sync for MutRef<T>

impl<T> Unpin for MutRef<T>

impl<T> UnwindSafe for MutRef<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.