Struct Unique

Source
pub struct Unique<T: ?Sized, A: Allocator = GlobalAllocator> { /* private fields */ }
Expand description

An allocator-aware smart pointer similar to C++’s unique_ptr.

§Usage

let pointer = Unique::new(100_000);
let num = *pointer;

TODO: Write better documentation.

Implementations§

Source§

impl<T, A: Allocator> Unique<T, A>

Source

pub fn new_with(value: T, allocator: A) -> Self

Source

pub fn pin_with(value: T, allocator: A) -> Pin<Self>

Source§

impl<T: ?Sized, A: Allocator> Unique<T, A>

Source

pub unsafe fn from_raw_with(pointer: NonNull<T>, allocator: A) -> Self

Source

pub fn leak<'a>(unique: Unique<T, A>) -> &'a mut T
where A: 'a,

Source

pub fn into_raw(unique: Self) -> *mut T

Source§

impl<T> Unique<T, GlobalAllocator>

Source

pub fn new(value: T) -> Self

Source

pub fn pin(value: T) -> Pin<Self>

Trait Implementations§

Source§

impl<T: ?Sized, A: Allocator> AsMut<T> for Unique<T, A>

Source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T: ?Sized, A: Allocator> AsRef<T> for Unique<T, A>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: ?Sized, A: Allocator> Borrow<T> for Unique<T, A>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: ?Sized, A: Allocator> BorrowMut<T> for Unique<T, A>

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T: ?Sized, A: Allocator> DerefMut for Unique<T, A>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: ?Sized, A: Allocator> Drop for Unique<T, A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<&str> for Unique<dyn BaseError>

Source§

fn from(value: &str) -> Self

Converts a str into a unique pointer of dyn BaseError.

Source§

impl<'a> From<&str> for Unique<dyn BaseError + Send + Sync + 'a>

Source§

fn from(value: &str) -> Self

Converts a str into a unique pointer of dyn BaseError + Send + Sync.

Source§

impl<'a, E: BaseError + 'a> From<E> for Unique<dyn BaseError + 'a>

Source§

fn from(value: E) -> Self

Converts a type of BaseError + Send + Sync into a unique pointer of dyn BaseError + Send + Sync.

Source§

impl From<String> for Unique<dyn BaseError>

Source§

fn from(value: String) -> Self

Converts a String into a unique pointer of dyn BaseError.

Source§

impl From<String> for Unique<dyn BaseError + Send + Sync>

Source§

fn from(value: String) -> Self

Converts a String into a unique pointer of dyn BaseError + Send + Sync.

Source§

impl<T: ?Sized, A: Allocator> Deref for Unique<T, A>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Unique<U, A>> for Unique<T, A>

Source§

impl<T: ?Sized, A: Allocator> Unpin for Unique<T, A>

Auto Trait Implementations§

§

impl<T, A> Freeze for Unique<T, A>
where A: Freeze, T: ?Sized,

§

impl<T, A> RefUnwindSafe for Unique<T, A>

§

impl<T, A = GlobalAllocator> !Send for Unique<T, A>

§

impl<T, A = GlobalAllocator> !Sync for Unique<T, A>

§

impl<T, A> UnwindSafe for Unique<T, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.