#[repr(C)]pub struct UniquePtr<T> where
T: UniquePtrTarget, { /* private fields */ }
Expand description
Binding to C++ std::unique_ptr<T, std::default_delete<T>>
.
Implementations
sourceimpl<T> UniquePtr<T> where
T: UniquePtrTarget,
impl<T> UniquePtr<T> where
T: UniquePtrTarget,
sourcepub fn null() -> Self
pub fn null() -> Self
Makes a new UniquePtr wrapping a null pointer.
Matches the behavior of default-constructing a std::unique_ptr.
sourcepub fn new(value: T) -> Self where
T: ExternType<Kind = Trivial>,
pub fn new(value: T) -> Self where
T: ExternType<Kind = Trivial>,
Allocates memory on the heap and makes a UniquePtr pointing to it.
sourcepub fn is_null(&self) -> bool
pub 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.
sourcepub fn as_ref(&self) -> Option<&T>
pub fn as_ref(&self) -> Option<&T>
Returns a reference to the object owned by this UniquePtr if any, otherwise None.
sourcepub fn as_mut(&mut self) -> Option<Pin<&mut T>>
pub 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.
sourcepub fn pin_mut(&mut self) -> Pin<&mut T>
pub 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.
sourcepub fn into_raw(self) -> *mut T
pub 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.
sourcepub unsafe fn from_raw(raw: *mut T) -> Self
pub 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
sourceimpl<T> Debug for UniquePtr<T> where
T: Debug + UniquePtrTarget,
impl<T> Debug for UniquePtr<T> where
T: Debug + UniquePtrTarget,
sourceimpl<T> Deref for UniquePtr<T> where
T: UniquePtrTarget,
impl<T> Deref for UniquePtr<T> where
T: UniquePtrTarget,
sourceimpl<T> DerefMut for UniquePtr<T> where
T: UniquePtrTarget + Unpin,
impl<T> DerefMut for UniquePtr<T> where
T: UniquePtrTarget + Unpin,
sourceimpl<T> Display for UniquePtr<T> where
T: Display + UniquePtrTarget,
impl<T> Display for UniquePtr<T> where
T: Display + UniquePtrTarget,
sourceimpl<T> Drop for UniquePtr<T> where
T: UniquePtrTarget,
impl<T> Drop for UniquePtr<T> where
T: UniquePtrTarget,
impl<T> Send for UniquePtr<T> where
T: Send + UniquePtrTarget,
impl<T> Sync for UniquePtr<T> where
T: Sync + UniquePtrTarget,
Auto Trait Implementations
impl<T> RefUnwindSafe for UniquePtr<T> where
T: RefUnwindSafe,
impl<T> Unpin for UniquePtr<T> where
T: Unpin,
impl<T> UnwindSafe for UniquePtr<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more