#[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() -> UniquePtr<T> ⓘ
pub fn null() -> UniquePtr<T> ⓘ
Makes a new UniquePtr wrapping a null pointer.
Matches the behavior of default-constructing a std::unique_ptr.
Sourcepub fn new(value: T) -> UniquePtr<T> ⓘwhere
T: ExternType<Kind = Trivial>,
pub fn new(value: T) -> UniquePtr<T> ⓘ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 as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Returns a raw const pointer to the object owned by this UniquePtr if any, otherwise the null pointer.
Sourcepub fn as_mut_ptr(&self) -> *mut T
pub fn as_mut_ptr(&self) -> *mut T
Returns a raw mutable pointer to the object owned by this UniquePtr if any, otherwise the null pointer.
As with std::unique_ptr<T>::get, this doesn’t require that you hold an exclusive reference to the UniquePtr. This differs from Rust norms, so extra care should be taken in the way the pointer is used.
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) -> UniquePtr<T> ⓘ
pub unsafe fn from_raw(raw: *mut T) -> UniquePtr<T> ⓘ
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> AsMove for UniquePtr<T>where
T: UniquePtrTarget + MakeCppStorage,
impl<T> AsMove for UniquePtr<T>where
T: UniquePtrTarget + MakeCppStorage,
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> Emplace<T> for UniquePtr<T>where
T: MakeCppStorage + UniquePtrTarget,
impl<T> Emplace<T> for UniquePtr<T>where
T: MakeCppStorage + UniquePtrTarget,
Source§impl<T> Ord for UniquePtr<T>where
T: Ord + UniquePtrTarget,
impl<T> Ord for UniquePtr<T>where
T: Ord + UniquePtrTarget,
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T> PartialOrd for UniquePtr<T>where
T: PartialOrd + UniquePtrTarget,
impl<T> PartialOrd for UniquePtr<T>where
T: PartialOrd + UniquePtrTarget,
Source§impl<T> Read for UniquePtr<T>
Forwarding Read
trait implementation in a manner similar to Box<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, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read moreSource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read moreSource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
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> Seek for UniquePtr<T>
Forwarding Seek
trait implementation in a manner similar to Box<T>
.
impl<T> Seek for UniquePtr<T>
Forwarding Seek
trait implementation in a manner similar to Box<T>
.
Note that the implementation will panic for null UniquePtr<T>
.
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>
Source§fn stream_position(&mut self) -> Result<u64, Error>
fn stream_position(&mut self) -> Result<u64, Error>
Source§impl<T> Write for UniquePtr<T>
Forwarding Write
trait implementation in a manner similar to Box<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, Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)