pub struct UniquePtr<T>where
T: Recyclable,{ /* private fields */ }Expand description
UniquePtr<T> holds a unique pointer to an object of type T and deletes the
object when the UniquePtr goes out of scope.
T must implement the Recyclable trait to define how the object is destroyed.
This allows UniquePtr to manage both Rust-allocated objects and C++-allocated
objects.
Implementations§
Source§impl<T: Recyclable> UniquePtr<T>
impl<T: Recyclable> UniquePtr<T>
Sourcepub unsafe fn from_raw(ptr: *mut T) -> Self
pub unsafe fn from_raw(ptr: *mut T) -> Self
Constructs a UniquePtr from a raw pointer.
§Safety
ptrmust be valid and the sole owning reference to the object pointed to byptr.ptrmust have been allocated in such a way that callingT::recycle(ptr)is a correct way to deallocate the pointer.
Sourcepub fn try_new(value: T) -> Result<UniquePtr<T>, AllocError>
pub fn try_new(value: T) -> Result<UniquePtr<T>, AllocError>
Helper function that allocates a new instance of T using T::allocate and
returns a UniquePtr wrapping it.
For Rust-allocated objects where T derives Recyclable, this will use
Box::try_new.
Sourcepub fn as_mut_ptr(this: &mut Self) -> *mut T
pub fn as_mut_ptr(this: &mut Self) -> *mut T
Returns a mutable raw pointer to the object.
Trait Implementations§
Source§impl<T: Recyclable> Deref for UniquePtr<T>
impl<T: Recyclable> Deref for UniquePtr<T>
Source§impl<T: Recyclable> DerefMut for UniquePtr<T>
impl<T: Recyclable> DerefMut for UniquePtr<T>
Source§impl<T: Recyclable> Drop for UniquePtr<T>
impl<T: Recyclable> Drop for UniquePtr<T>
Source§impl<T: Recyclable> PtrTraits for UniquePtr<T>
impl<T: Recyclable> PtrTraits for UniquePtr<T>
impl<T: Recyclable> ManagedPtr for UniquePtr<T>
impl<T: Recyclable + Send> Send for UniquePtr<T>
impl<T: Recyclable + Sync> Sync for UniquePtr<T>
Auto Trait Implementations§
impl<T> Freeze for UniquePtr<T>
impl<T> RefUnwindSafe for UniquePtr<T>where
T: RefUnwindSafe,
impl<T> Unpin for UniquePtr<T>
impl<T> UnsafeUnpin for UniquePtr<T>
impl<T> UnwindSafe for UniquePtr<T>where
T: RefUnwindSafe,
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
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
Initializes
slot. Read more