#[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§
Source§impl<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) -> Selfwhere
T: ExternType<Kind = Trivial>,
pub fn new(value: T) -> Selfwhere
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§
Source§impl<T> Deref for UniquePtr<T>where
T: UniquePtrTarget,
impl<T> Deref for UniquePtr<T>where
T: UniquePtrTarget,
Source§impl<T> Drop for UniquePtr<T>where
T: UniquePtrTarget,
impl<T> Drop for UniquePtr<T>where
T: UniquePtrTarget,
Source§impl<T> Read for UniquePtr<T>
impl<T> Read for UniquePtr<T>
Forwarding Read
trait implementation in a manner similar to Box<T>
.
Note that the implementation will panic for null UniquePtr<T>
.
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf
. Read moreSource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf
. Read moreSource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read more1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)Source§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl<T> Write for UniquePtr<T>
impl<T> Write for UniquePtr<T>
Forwarding Write
trait implementation in a manner similar to Box<T>
.
Note that the implementation will panic for null UniquePtr<T>
.
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
Source§fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)