#[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 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> 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, 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> 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, 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
)impl<T> Send for UniquePtr<T>where
T: Send + UniquePtrTarget,
impl<T> Sync for UniquePtr<T>where
T: Sync + UniquePtrTarget,
impl<T> Unpin for UniquePtr<T>where
T: UniquePtrTarget,
Auto Trait Implementations§
impl<T> Freeze for UniquePtr<T>
impl<T> RefUnwindSafe for UniquePtr<T>where
T: RefUnwindSafe,
impl<T> UnwindSafe for UniquePtr<T>where
T: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R> Rng for R
impl<R> Rng for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform
distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T> ⓘ
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T> ⓘ
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p
of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator
of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T> ⓘwhere
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T> ⓘwhere
D: Distribution<T>,
Self: Sized,
Source§fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
random
to avoid conflict with the new gen
keyword in Rust 2024.Rng::random
.Source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
random_range
Rng::random_range
.Source§impl<R> TryRngCore for Rwhere
R: RngCore,
impl<R> TryRngCore for Rwhere
R: RngCore,
Source§type Error = Infallible
type Error = Infallible
Source§fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
u32
.Source§fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
u64
.Source§fn try_fill_bytes(
&mut self,
dst: &mut [u8],
) -> Result<(), <R as TryRngCore>::Error>
fn try_fill_bytes( &mut self, dst: &mut [u8], ) -> Result<(), <R as TryRngCore>::Error>
dest
entirely with random data.Source§fn read_adapter(&mut self) -> RngReadAdapter<'_, Self> ⓘwhere
Self: Sized,
fn read_adapter(&mut self) -> RngReadAdapter<'_, Self> ⓘwhere
Self: Sized,
RngCore
to a RngReadAdapter
.