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>
impl<T> UniquePtr<T>
Sourcepub unsafe fn new(ptr: *mut T, drop_fn: unsafe fn(*mut T)) -> Self
pub unsafe fn new(ptr: *mut T, drop_fn: unsafe fn(*mut T)) -> Self
Create a new UniquePtr from a raw pointer.
§Safety
ptrmust be a valid, uniquely-owned pointer or NULL.drop_fnmust correctly free the pointed-to object.- No other code may hold a reference to this pointer.
Sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Get a raw pointer (for FFI calls). The caller must not free the pointer.
Sourcepub fn as_mut_ptr(&mut self) -> *mut T
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.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Send for UniquePtr<T>
impl<T> !Sync for UniquePtr<T>
impl<T> Freeze for UniquePtr<T>
impl<T> RefUnwindSafe for UniquePtr<T>
impl<T> Unpin for UniquePtr<T>
impl<T> UnsafeUnpin for UniquePtr<T>
impl<T> UnwindSafe for UniquePtr<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more