[−][src]Struct cpp_core::Ref
A non-null, mutable pointer to a C++ object (similar to a C++ reference).
Ref
never owns its content.
Note that unlike Rust references, Ref
can be freely copied,
producing multiple mutable pointers to the same object, which is usually necessary
to do when working with C++ libraries.
Ref
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+
.
Ref
implements Deref
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,
Ref
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 Ref
exists. Note that
with Ref
, 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
Ref
in a safe interface.
Methods
impl<T> Ref<T>
[src]
pub unsafe fn new(ptr: Ptr<T>) -> Option<Self>
[src]
Creates a Ref
from a Ptr
. Returns None
if ptr
is null.
Safety
ptr
must be valid. See type level documentation.
pub unsafe fn from_raw(ptr: *const T) -> Option<Self>
[src]
Creates a Ref
from a raw pointer. Returns None
if ptr
is null.
Safety
ptr
must be valid. See type level documentation.
pub unsafe fn from_raw_non_null(ptr: NonNull<T>) -> Self
[src]
pub unsafe fn as_ptr(self) -> Ptr<T>
[src]
pub unsafe fn as_raw_ref<'a>(self) -> &'a T
[src]
Returns a reference to the value.
Safety
self
must be valid.
The content must not be read or modified through other ways while the returned reference
exists.See type level documentation.
pub unsafe fn as_mut_raw_ref<'a>(self) -> &'a mut T
[src]
Returns a mutable reference to the value.
Safety
self
must be valid.
The content must not be read or modified through other ways while the returned reference
exists.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 constant raw pointer to the value.
pub unsafe fn static_upcast<U>(self) -> Ref<U> where
T: StaticUpcast<U>,
[src]
T: StaticUpcast<U>,
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]
T: StaticDowncast<U>,
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]
T: DynamicCast<U>,
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.
impl<V, T> Ref<V> where
V: Data<Output = *const T> + Size,
[src]
V: Data<Output = *const T> + Size,
pub unsafe fn as_slice<'a>(self) -> &'a [T]
[src]
Returns the content of the object as a slice, based on data()
and size()
methods.
Safety
The caller must make sure self
contains a valid pointer. The content must
not be read or modified through other ways while the returned slice exists.
This function
may invoke arbitrary foreign code, so no safety guarantees can be made.
impl<V, T> Ref<V> where
V: DataMut<Output = *mut T> + Size,
[src]
V: DataMut<Output = *mut T> + Size,
pub unsafe fn as_mut_slice<'a>(self) -> &'a mut [T]
[src]
Returns the content of the vector as a mutable slice,
based on data()
and size()
methods.
Safety
The caller must make sure self
contains a valid pointer. The content must
not be read or modified through other ways while the returned slice exists.
This function
may invoke arbitrary foreign code, so no safety guarantees can be made.
impl<T, T1, T2> Ref<T> where
T: Begin<Output = CppBox<T1>> + End<Output = CppBox<T2>>,
T1: CppDeletable + PartialEq<Ref<T2>> + Increment + Indirection,
T2: CppDeletable,
[src]
T: Begin<Output = CppBox<T1>> + End<Output = CppBox<T2>>,
T1: CppDeletable + PartialEq<Ref<T2>> + Increment + Indirection,
T2: CppDeletable,
pub unsafe fn iter(self) -> CppIterator<T1, T2>
[src]
Returns an iterator over the content of the object,
based on begin()
and end()
methods.
Safety
The caller must make sure self
contains a valid pointer. The content must
not be read or modified through other ways while the returned slice exists.
This function
may invoke arbitrary foreign code, so no safety guarantees can be made.
impl<T, T1, T2> Ref<T> where
T: BeginMut<Output = CppBox<T1>> + EndMut<Output = CppBox<T2>>,
T1: CppDeletable + PartialEq<Ref<T2>> + Increment + Indirection,
T2: CppDeletable,
[src]
T: BeginMut<Output = CppBox<T1>> + EndMut<Output = CppBox<T2>>,
T1: CppDeletable + PartialEq<Ref<T2>> + Increment + Indirection,
T2: CppDeletable,
pub unsafe fn iter_mut(self) -> CppIterator<T1, T2>
[src]
Returns a mutable iterator over the content of the object,
based on begin()
and end()
methods.
Safety
The caller must make sure self
contains a valid pointer. The content must
not be read or modified through other ways while the returned slice exists.
This function
may invoke arbitrary foreign code, so no safety guarantees can be made.
Trait Implementations
impl<T: 'static, U> Add<U> for Ref<T> where
&'static T: Add<U>,
[src]
&'static T: Add<U>,
type Output = <&'static T as Add<U>>::Output
The resulting type after applying the +
operator.
fn add(self, rhs: U) -> Self::Output
[src]
impl<T: 'static, U> BitAnd<U> for Ref<T> where
&'static T: BitAnd<U>,
[src]
&'static T: BitAnd<U>,
type Output = <&'static T as BitAnd<U>>::Output
The resulting type after applying the &
operator.
fn bitand(self, rhs: U) -> Self::Output
[src]
impl<T: 'static, U> BitOr<U> for Ref<T> where
&'static T: BitOr<U>,
[src]
&'static T: BitOr<U>,
type Output = <&'static T as BitOr<U>>::Output
The resulting type after applying the |
operator.
fn bitor(self, rhs: U) -> Self::Output
[src]
impl<T: 'static, U> BitXor<U> for Ref<T> where
&'static T: BitXor<U>,
[src]
&'static T: BitXor<U>,
type Output = <&'static T as BitXor<U>>::Output
The resulting type after applying the ^
operator.
fn bitxor(self, rhs: U) -> Self::Output
[src]
impl<'a, T, U: CppDeletable> CastFrom<&'a CppBox<U>> for Ref<T> where
U: StaticUpcast<T>,
[src]
U: StaticUpcast<T>,
impl<T, U> CastFrom<Ref<U>> for Ptr<T> where
U: StaticUpcast<T>,
[src]
U: StaticUpcast<T>,
impl<T, U> CastFrom<Ref<U>> for Ref<T> where
U: StaticUpcast<T>,
[src]
U: StaticUpcast<T>,
impl<T> Clone for Ref<T>
[src]
Creates another pointer to the same object.
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T> Copy for Ref<T>
[src]
Creates another pointer to the same object.
impl<T> Debug for Ref<T>
[src]
impl<T> Deref for Ref<T>
[src]
Allows to call member functions of T
and its base classes directly on the pointer.
impl<T: 'static, U> Div<U> for Ref<T> where
&'static T: Div<U>,
[src]
&'static T: Div<U>,
type Output = <&'static T as Div<U>>::Output
The resulting type after applying the /
operator.
fn div(self, rhs: U) -> Self::Output
[src]
impl<T: 'static, U> Mul<U> for Ref<T> where
&'static T: Mul<U>,
[src]
&'static T: Mul<U>,
type Output = <&'static T as Mul<U>>::Output
The resulting type after applying the *
operator.
fn mul(self, rhs: U) -> Self::Output
[src]
impl<T, U> PartialEq<U> for Ref<T> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
impl<T, U> PartialOrd<U> for Ref<T> where
T: Lt<U> + Le<U> + Gt<U> + Ge<U> + PartialEq<U>,
[src]
T: Lt<U> + Le<U> + Gt<U> + Ge<U> + PartialEq<U>,
fn partial_cmp(&self, other: &U) -> Option<Ordering>
[src]
fn lt(&self, other: &U) -> bool
[src]
fn le(&self, other: &U) -> bool
[src]
fn gt(&self, other: &U) -> bool
[src]
fn ge(&self, other: &U) -> bool
[src]
impl<T: 'static, U> Rem<U> for Ref<T> where
&'static T: Rem<U>,
[src]
&'static T: Rem<U>,
type Output = <&'static T as Rem<U>>::Output
The resulting type after applying the %
operator.
fn rem(self, rhs: U) -> Self::Output
[src]
impl<T: 'static, U> Shl<U> for Ref<T> where
&'static T: Shl<U>,
[src]
&'static T: Shl<U>,
type Output = <&'static T as Shl<U>>::Output
The resulting type after applying the <<
operator.
fn shl(self, rhs: U) -> Self::Output
[src]
impl<T: 'static, U> Shr<U> for Ref<T> where
&'static T: Shr<U>,
[src]
&'static T: Shr<U>,
type Output = <&'static T as Shr<U>>::Output
The resulting type after applying the >>
operator.
fn shr(self, rhs: U) -> Self::Output
[src]
impl<T: 'static, U> Sub<U> for Ref<T> where
&'static T: Sub<U>,
[src]
&'static T: Sub<U>,
Auto Trait Implementations
impl<T> RefUnwindSafe for Ref<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> !Send for Ref<T>
impl<T> !Sync for Ref<T>
impl<T> Unpin for Ref<T>
impl<T> UnwindSafe for Ref<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,