[−][src]Struct cpp_core::MutPtr
A mutable pointer to a C++ object (similar to a C++ pointer).
A MutPtr
may or may not be owned. If you actually own the object, it's recommended to
convert it to CppBox
using to_box
method.
Note that unlike Rust references, MutPtr
can be freely copied,
producing multiple mutable pointers to the same object, which is usually necessary
to do when working with C++ libraries.
MutPtr
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+
.
MutPtr
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.
MutPtr
can contain a null pointer. Deref
and DerefMut
will panic if attempted to dereference a null pointer.
If the object provides an iterator interface through begin()
and end()
functions,
MutPtr
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 MutPtr
exists. Note that
with MutPtr
, 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
MutPtr
in a safe interface.
Null pointers must not be dereferenced.
Methods
impl<T> MutPtr<T>
[src]
pub unsafe fn from_raw(ptr: *mut T) -> Self
[src]
pub unsafe fn null() -> Self
[src]
Creates a null pointer.
Note that accessing the content of a null MutPtr
through Deref
or DerefMut
will result in a panic.
Note that you can also use NullPtr
to specify a null pointer to a function accepting
impl CastInto<MutPtr<_>>
. Unlike MutPtr
, NullPtr
is not a generic type, so it will
not cause type inference issues.
Safety
Null pointers must not be dereferenced. See type level documentation.
pub fn as_raw_ptr(self) -> *const T
[src]
Returns the content as a raw const pointer.
pub fn as_mut_raw_ptr(self) -> *mut T
[src]
Returns the content as a raw mutable pointer.
pub unsafe fn as_ptr(self) -> Ptr<T>
[src]
Returns the content as a const Ptr
.
Safety
The operation is safe as long as self
is valid or null. See type level documentation.
pub unsafe fn as_ref(self) -> Option<Ref<T>>
[src]
Returns the content as a const Ref
. Returns None
if self
is a null pointer.
Safety
The operation is safe as long as self
is valid or null. See type level documentation.
pub unsafe fn as_mut_ref(self) -> Option<MutRef<T>>
[src]
Returns the content as a MutRef
. Returns None
if self
is a null pointer.
Safety
The operation is safe as long as self
is valid or null. See type level documentation.
pub fn is_null(self) -> bool
[src]
Returns true if the pointer is null.
pub unsafe fn static_upcast<U>(self) -> Ptr<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 or null.
pub unsafe fn static_downcast<U>(self) -> Ptr<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
,
of if self
is a null pointer.
pub unsafe fn dynamic_cast<U>(self) -> Ptr<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 or null.
pub unsafe fn static_upcast_mut<U>(self) -> MutPtr<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 or null.
pub unsafe fn static_downcast_mut<U>(self) -> MutPtr<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
,
of if self
is a null pointer.
pub unsafe fn dynamic_cast_mut<U>(self) -> MutPtr<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 or null.
impl<T: CppDeletable> MutPtr<T>
[src]
pub unsafe fn to_box(self) -> Option<CppBox<T>>
[src]
Converts this pointer to a CppBox
. Returns None
if self
is a null pointer.
Use this function to take ownership of the object. This is
the same as CppBox::new
.
Safety
See type level documentation. See also CppBox::new
documentation.
impl MutPtr<c_char>
[src]
pub unsafe fn from_c_str(str: &CStr) -> Self
[src]
Creates a MutPtr<c_char>
, i.e. C++'s char*
from a CStr
.
Safety
The source str
must be valid
while MutPtr
exists and while
it's used by the C++ library.
After passing str
to MutPtr
, it's unsafe to use str
and
any references to the same buffer from Rust because
the memory can be modified through MutPtr
.
pub unsafe fn to_c_str<'a>(self) -> &'a CStr
[src]
Converts MutPtr<c_char>
, i.e. C++'s char*
to a &CStr
.
Safety
No guarantees can be made about the validity and lifetime of the buffer, since it could be produced by a C++ library.
Trait Implementations
impl<T: 'static, U> Add<U> for MutPtr<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> AddAssign<U> for MutPtr<T> where
T: AddAssign<U>,
[src]
T: AddAssign<U>,
fn add_assign(&mut self, rhs: U)
[src]
impl<T: 'static, U> BitAnd<U> for MutPtr<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> BitAndAssign<U> for MutPtr<T> where
T: BitAndAssign<U>,
[src]
T: BitAndAssign<U>,
fn bitand_assign(&mut self, rhs: U)
[src]
impl<T: 'static, U> BitOr<U> for MutPtr<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> BitOrAssign<U> for MutPtr<T> where
T: BitOrAssign<U>,
[src]
T: BitOrAssign<U>,
fn bitor_assign(&mut self, rhs: U)
[src]
impl<T: 'static, U> BitXor<U> for MutPtr<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<T: 'static, U> BitXorAssign<U> for MutPtr<T> where
T: BitXorAssign<U>,
[src]
T: BitXorAssign<U>,
fn bitxor_assign(&mut self, rhs: U)
[src]
impl<'a> CastFrom<&'a CStr> for MutPtr<c_char>
[src]
impl<'a, T, U: CppDeletable> CastFrom<&'a mut CppBox<U>> for MutPtr<T> where
U: StaticUpcast<T>,
[src]
U: StaticUpcast<T>,
impl<T, U> CastFrom<*mut U> for MutPtr<T> where
U: StaticUpcast<T>,
[src]
U: StaticUpcast<T>,
impl<T, U> CastFrom<MutPtr<U>> for Ptr<T> where
U: StaticUpcast<T>,
[src]
U: StaticUpcast<T>,
impl<T, U> CastFrom<MutPtr<U>> for MutPtr<T> where
U: StaticUpcast<T>,
[src]
U: StaticUpcast<T>,
impl<T, U> CastFrom<MutRef<U>> for MutPtr<T> where
U: StaticUpcast<T>,
[src]
U: StaticUpcast<T>,
impl<T> CastFrom<NullPtr> for MutPtr<T>
[src]
impl<T> Clone for MutPtr<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 MutPtr<T>
[src]
Creates another pointer to the same object.
impl<T> Debug for MutPtr<T>
[src]
impl<T> Deref for MutPtr<T>
[src]
Allows to call member functions of T
and its base classes directly on the pointer.
Panics if the pointer is null.
impl<T> DerefMut for MutPtr<T>
[src]
Allows to call member functions of T
and its base classes directly on the pointer.
Panics if the pointer is null.
impl<T: 'static, U> Div<U> for MutPtr<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> DivAssign<U> for MutPtr<T> where
T: DivAssign<U>,
[src]
T: DivAssign<U>,
fn div_assign(&mut self, rhs: U)
[src]
impl<T, T1, T2> IntoIterator for MutPtr<T> where
T: BeginMut<Output = CppBox<T1>> + EndMut<Output = CppBox<T2>>,
T1: CppDeletable + PartialEq<Ref<T2>> + Indirection + Increment,
T2: CppDeletable,
[src]
T: BeginMut<Output = CppBox<T1>> + EndMut<Output = CppBox<T2>>,
T1: CppDeletable + PartialEq<Ref<T2>> + Indirection + Increment,
T2: CppDeletable,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T: 'static, U> Mul<U> for MutPtr<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: 'static, U> MulAssign<U> for MutPtr<T> where
T: MulAssign<U>,
[src]
T: MulAssign<U>,
fn mul_assign(&mut self, rhs: U)
[src]
impl<T, U> PartialEq<U> for MutPtr<T> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
impl<T, U> PartialOrd<U> for MutPtr<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 MutPtr<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> RemAssign<U> for MutPtr<T> where
T: RemAssign<U>,
[src]
T: RemAssign<U>,
fn rem_assign(&mut self, rhs: U)
[src]
impl<T: 'static, U> Shl<U> for MutPtr<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> ShlAssign<U> for MutPtr<T> where
T: ShlAssign<U>,
[src]
T: ShlAssign<U>,
fn shl_assign(&mut self, rhs: U)
[src]
impl<T: 'static, U> Shr<U> for MutPtr<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> ShrAssign<U> for MutPtr<T> where
T: ShrAssign<U>,
[src]
T: ShrAssign<U>,
fn shr_assign(&mut self, rhs: U)
[src]
impl<T: 'static, U> Sub<U> for MutPtr<T> where
&'static T: Sub<U>,
[src]
&'static T: Sub<U>,
type Output = <&'static T as Sub<U>>::Output
The resulting type after applying the -
operator.
fn sub(self, rhs: U) -> Self::Output
[src]
impl<T: 'static, U> SubAssign<U> for MutPtr<T> where
T: SubAssign<U>,
[src]
T: SubAssign<U>,
fn sub_assign(&mut self, rhs: U)
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for MutPtr<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> !Send for MutPtr<T>
impl<T> !Sync for MutPtr<T>
impl<T> Unpin for MutPtr<T>
impl<T> UnwindSafe for MutPtr<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<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
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>,