Struct OwnedAlloc

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

Dynamic allocation of a T whose memory is considered fully initialized. The allocation and its content are freed on drop. Similar to a Box. 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> OwnedAlloc<T>

Source

pub fn new(val: T) -> Self

Creates an allocation and initializes it to the passed argument. In case of allocation error, the handler registered via stdlib is called.

Source

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

Creates an allocation and initializes it to the passed argument. In case of allocation error, Err is returned.

Source

pub fn move_inner(self) -> (T, UninitAlloc<T>)

Moves the stored value out from the allocation. The value and the allocation now considered uninitialized are returned.

Source§

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

Source

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

Recreate the OwnedAlloc from a raw non-null pointer.

§Safety

This functions is unsafe because passing the wrong pointer leads to undefined behaviour. Passing a pointer to uninitialized memory is also undefined behaviour.

Source

pub unsafe fn from_box(boxed: Box<T>) -> Self

Converts the plain old standard library Box into an owned allocation.

§Safety

This function is unsafe because there are no guarantees that Box and OwnedAlloc allocate in the same way. They probably do in the Rust version you are using, but there are no future guarantees.

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 both the allocation and its content and returns its raw non-null pointer.

Source

pub unsafe fn into_box(self) -> Box<T>

Converts the owned allocation into a plain old standard library Box.

§Safety

This function is unsafe because there are no guarantees that Box and OwnedAlloc allocate in the same way. They probably do in the Rust version you are using, but there are no future guarantees.

Source

pub fn drop_in_place(self) -> UninitAlloc<T>

Drops the memory and returns the allocation now considered uninitialized.

Source

pub fn forget_inner(self) -> UninitAlloc<T>

“Forgets” about dropping the inner value and returns an uninitialized allocation.

Trait Implementations§

Source§

impl<T> Clone for OwnedAlloc<T>
where T: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

Source§

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

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

impl<T> Deref for OwnedAlloc<T>
where T: ?Sized,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T> DerefMut for OwnedAlloc<T>
where T: ?Sized,

Source§

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

Mutably dereferences the value.
Source§

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl<T> From<T> for OwnedAlloc<T>

Source§

fn from(val: T) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<T> UnwindSafe for OwnedAlloc<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.