Struct UniquePtr

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

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

Implementations

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

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) -> 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) -> Option<&T>

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

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.

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.

fn as_ptr(&self) -> *const T

Returns a raw const pointer to the object owned by this UniquePtr if any, otherwise the null pointer.

fn as_mut_ptr(&self) -> *mut T

Returns a raw mutable pointer to the object owned by this UniquePtr if any, otherwise the null pointer.

As with std::unique_ptr<T>::get, this doesn't require that you hold an exclusive reference to the UniquePtr. This differs from Rust norms, so extra care should be taken in the way the pointer is used.

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.

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

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

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

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

type Target = T;
fn deref(&self) -> &Self::Target

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

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

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

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

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

fn drop(&mut self)

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

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

fn hash<H>(&self, hasher: &mut H)
where
    H: Hasher,

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

fn cmp(&self, other: &Self) -> Ordering

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

fn eq(&self, other: &Self) -> bool

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

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

impl<T> Read for UniquePtr<T> where for<'a> Pin<&'a mut T>: Read, T: UniquePtrTarget,

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

impl<T> Seek for UniquePtr<T> where for<'a> Pin<&'a mut T>: Seek, T: UniquePtrTarget,

fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn rewind(&mut self) -> Result<()>
fn stream_position(&mut self) -> Result<u64>
fn seek_relative(&mut self, offset: i64) -> Result<()>

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

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

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

impl<T> Write for UniquePtr<T> where for<'a> Pin<&'a mut T>: Write, T: UniquePtrTarget,

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

Auto Trait Implementations

impl<T> Freeze for UniquePtr<T> where PhantomData<T>: Freeze,

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

impl<T> UnsafeUnpin for UniquePtr<T> where PhantomData<T>: UnsafeUnpin,

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

Blanket Implementations

impl<P, T> Receiver for UniquePtr<T> where P: Deref<Target = T> + ?Sized, T: ?Sized,

type Target = T;

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for UniquePtr<T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for UniquePtr<T> where T: ?Sized,

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

impl<T> From<T> for UniquePtr<T>

fn from(t: T) -> T

Returns the argument unchanged.

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

fn to_string(&self) -> String

impl<T, U> Into<U> for UniquePtr<T> where U: From<T>,

fn into(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<U> for UniquePtr<T> where U: Into<T>,

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

impl<T, U> TryInto<U> for UniquePtr<T> where U: TryFrom<T>,

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