Skip to main content

UniquePtr

Struct UniquePtr 

Source
pub struct UniquePtr<T> { /* private fields */ }
Expand description

A wrapper around a raw pointer that enforces single ownership.

When UniquePtr<T> is dropped, it frees the underlying object using the provided DropFn.

§Safety

This is an internal helper for the ABI membrane. It should not be exposed to external callers.

Implementations§

Source§

impl<T> UniquePtr<T>

Source

pub unsafe fn new(ptr: *mut T, drop_fn: unsafe fn(*mut T)) -> Self

Create a new UniquePtr from a raw pointer.

§Safety
  • ptr must be a valid, uniquely-owned pointer or NULL.
  • drop_fn must correctly free the pointed-to object.
  • No other code may hold a reference to this pointer.
Source

pub fn as_ptr(&self) -> *const T

Get a raw pointer (for FFI calls). The caller must not free the pointer.

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Get a mutable raw pointer (for FFI calls that mutate). The caller must not free the pointer.

Source

pub fn into_raw(self) -> *mut T

Release ownership and return the raw pointer. The caller is now responsible for freeing it.

Trait Implementations§

Source§

impl<T> Drop for UniquePtr<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !Send for UniquePtr<T>

§

impl<T> !Sync for UniquePtr<T>

§

impl<T> Freeze for UniquePtr<T>
where Option<NonNull<T>>: Freeze, unsafe fn(*mut T): Freeze,

§

impl<T> RefUnwindSafe for UniquePtr<T>

§

impl<T> Unpin for UniquePtr<T>
where Option<NonNull<T>>: Unpin, unsafe fn(*mut T): Unpin,

§

impl<T> UnsafeUnpin for UniquePtr<T>

§

impl<T> UnwindSafe for UniquePtr<T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.