Struct UninitAlloc

Source
pub struct UninitAlloc<T>
where T: ?Sized,
{ /* private fields */ }
Expand description

Dynamic allocation of a T whose memory is considered uninitialized. The allocation is freed on drop. If the size of the allocation is zero, no allocation is performed and a dangling pointer is used (just like in std). For the drop checker, the type acts as if it contains a T due to usage of PhantomData<T>.

Implementations§

Source§

impl<T> UninitAlloc<T>

Source

pub fn new() -> Self

Creates room for a T. In case of allocation error, the handler registered via stdlib is called.

Source

pub fn try_new() -> Result<Self, AllocErr>

Creates room for a T. In case of allocation error, Err is returned.

Source

pub fn init(self, val: T) -> OwnedAlloc<T>

Initializes the memory and returns the allocation now considered initialized.

Source§

impl<T> UninitAlloc<T>
where T: ?Sized,

Source

pub unsafe fn init_in_place<F>(self, init: F) -> OwnedAlloc<T>
where F: FnOnce(&mut T),

Calls a function with a mutable reference to uninitialized memory and returns the allocation now considered initialized. The passed function is expected to initialize the memory.

§Safety

This function is unsafe because the passed function might not initialize the memory correctly.

Source

pub unsafe fn from_raw(nnptr: NonNull<T>) -> Self

Recreate the UninitAlloc from a raw non-null pointer.

§Safety

This functions is unsafe because passing the wrong pointer leads to undefined behaviour.

Source

pub fn raw(&self) -> NonNull<T>

Returns the raw non-null pointer of the allocation.

Source

pub fn into_raw(self) -> NonNull<T>

“Forgets” dropping the allocation and returns its raw non-null pointer.

Trait Implementations§

Source§

impl<T> Debug for UninitAlloc<T>
where T: ?Sized,

Source§

fn fmt(&self, fmtr: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for UninitAlloc<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for UninitAlloc<T>
where T: ?Sized,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> From<RawVec<T>> for UninitAlloc<[T]>

Source§

fn from(alloc: RawVec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<UninitAlloc<T>> for MaybeUninitAlloc<T>
where T: ?Sized,

Source§

fn from(alloc: UninitAlloc<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<UninitAlloc<T>> for RawVec<T>

Source§

fn from(alloc: UninitAlloc<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> Send for UninitAlloc<T>
where T: ?Sized + Send,

Source§

impl<T> Sync for UninitAlloc<T>
where T: ?Sized + Sync,

Auto Trait Implementations§

§

impl<T> Freeze for UninitAlloc<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for UninitAlloc<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Unpin for UninitAlloc<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for UninitAlloc<T>

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<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.