Struct cxx::UniquePtr

source ·
#[repr(C)]
pub struct UniquePtr<T>where T: UniquePtrTarget,{ /* private fields */ }
Expand description

Binding to C++ std::unique_ptr<T, std::default_delete<T>>.

Implementations§

source§

impl<T> UniquePtr<T>where T: UniquePtrTarget,

source

pub fn null() -> Self

Makes a new UniquePtr wrapping a null pointer.

Matches the behavior of default-constructing a std::unique_ptr.

source

pub fn new(value: T) -> Selfwhere T: ExternType<Kind = Trivial>,

Allocates memory on the heap and makes a UniquePtr pointing to it.

source

pub fn is_null(&self) -> bool

Checks whether the UniquePtr does not own an object.

This is the opposite of std::unique_ptr<T>::operator bool.

source

pub fn as_ref(&self) -> Option<&T>

Returns a reference to the object owned by this UniquePtr if any, otherwise None.

source

pub fn as_mut(&mut self) -> Option<Pin<&mut T>>

Returns a mutable pinned reference to the object owned by this UniquePtr if any, otherwise None.

source

pub fn pin_mut(&mut self) -> Pin<&mut T>

Returns a mutable pinned reference to the object owned by this UniquePtr.

Panics

Panics if the UniquePtr holds a null pointer.

source

pub fn into_raw(self) -> *mut T

Consumes the UniquePtr, releasing its ownership of the heap-allocated T.

Matches the behavior of std::unique_ptr<T>::release.

source

pub unsafe fn from_raw(raw: *mut T) -> Self

Constructs a UniquePtr retaking ownership of a pointer previously obtained from into_raw.

Safety

This function is unsafe because improper use may lead to memory problems. For example a double-free may occur if the function is called twice on the same raw pointer.

Trait Implementations§

source§

impl<T> Debug for UniquePtr<T>where T: Debug + UniquePtrTarget,

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Deref for UniquePtr<T>where T: UniquePtrTarget,

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T> DerefMut for UniquePtr<T>where T: UniquePtrTarget + Unpin,

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<T> Display for UniquePtr<T>where T: Display + UniquePtrTarget,

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Drop for UniquePtr<T>where T: UniquePtrTarget,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T> Send for UniquePtr<T>where T: Send + UniquePtrTarget,

source§

impl<T> Sync for UniquePtr<T>where T: Sync + UniquePtrTarget,

source§

impl<T> Unpin for UniquePtr<T>where T: UniquePtrTarget,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for UniquePtr<T>where T: RefUnwindSafe,

§

impl<T> UnwindSafe for UniquePtr<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.