Struct UniquePtr

struct UniquePtr<T> { ... }
where
    T: UniquePtrTarget

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

Implementations

impl<T> UniquePtr<T>

fn null() -> Self

Makes a new UniquePtr wrapping a null pointer.

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

fn new(value: T) -> Self
where
    T: ExternType<Kind = Trivial>

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

fn is_null(self: &Self) -> bool

Checks whether the UniquePtr does not own an object.

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

fn as_ref(self: &Self) -> Option<&T>

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

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

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

fn pin_mut(self: &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.

fn into_raw(self: Self) -> *mut T

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

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

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.

impl<P, T> Receiver for UniquePtr<T>

impl<T> Any for UniquePtr<T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for UniquePtr<T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for UniquePtr<T>

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

impl<T> Debug for UniquePtr<T>

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

impl<T> Deref for UniquePtr<T>

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

impl<T> DerefMut for UniquePtr<T>

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

impl<T> Display for UniquePtr<T>

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

impl<T> Drop for UniquePtr<T>

fn drop(self: &mut Self)

impl<T> Freeze for UniquePtr<T>

impl<T> From for UniquePtr<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Read for UniquePtr<T>

fn read(self: &mut Self, buf: &mut [u8]) -> Result<usize>
fn read_to_end(self: &mut Self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_string(self: &mut Self, buf: &mut String) -> Result<usize>
fn read_exact(self: &mut Self, buf: &mut [u8]) -> Result<()>

impl<T> RefUnwindSafe for UniquePtr<T>

impl<T> Send for UniquePtr<T>

impl<T> Sync for UniquePtr<T>

impl<T> ToString for UniquePtr<T>

fn to_string(self: &Self) -> String

impl<T> Unpin for UniquePtr<T>

impl<T> UnsafeUnpin for UniquePtr<T>

impl<T> UnwindSafe for UniquePtr<T>

impl<T> Write for UniquePtr<T>

fn write(self: &mut Self, buf: &[u8]) -> Result<usize>
fn write_vectored(self: &mut Self, bufs: &[IoSlice<'_>]) -> Result<usize>
fn flush(self: &mut Self) -> Result<()>
fn write_all(self: &mut Self, buf: &[u8]) -> Result<()>
fn write_fmt(self: &mut Self, fmt: Arguments<'_>) -> Result<()>

impl<T, U> Into for UniquePtr<T>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for UniquePtr<T>

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

impl<T, U> TryInto for UniquePtr<T>

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