Struct Emplace

Source
pub struct Emplace<'a, A, T, R = &'a mut T, S = &'a mut [T]> { /* private fields */ }
Expand description

Provides interface for emplacing values. Created by Blink::emplace, Blink::emplace_no_drop and Blink::emplace_unchecked.

Implementations§

Source§

impl<'a, A, T, R, S> Emplace<'a, A, T, R, S>
where A: BlinkAllocator, T: 'a, R: CoerceFromMut<'a, T>, S: CoerceFromMut<'a, [T]>,

Source

pub fn try_value(&self, value: T) -> Result<R, T>

Allocates memory for a value and moves value into the memory. If allocation fails, returns Err(value). On success returns reference to the emplaced value.

Source

pub fn value(&self, value: T) -> R

Allocates memory for a value and moves value into the memory. Returns reference to the emplaced value. If allocation fails, diverges.

Source

pub fn try_with<F>(&self, f: F) -> Result<R, F>
where F: FnOnce() -> T,

Allocates memory for a value. On success invokes closure and initialize the value. Returns reference to the value. If allocation fails, returns error with closure.

Source

pub fn with<F>(&self, f: F) -> R
where F: FnOnce() -> T,

Allocates memory for a value. On success invokes closure and initialize the value. Returns reference to the value. If allocation fails, diverges.

Source

pub fn try_with_fallible<F, E>(&self, f: F) -> Result<R, Result<E, F>>
where F: FnOnce() -> Result<T, E>, E: 'a,

Allocates memory for a value. If allocation fails, returns error with closure. On success invokes closure and initialize the value. If closure fails, returns the error. Returns reference to the value.

Source

pub fn with_fallible<F, E>(&self, f: F) -> Result<R, E>
where F: FnOnce() -> Result<T, E>, E: 'a,

Allocates memory for a value. If allocation fails, returns error with closure. On success invokes closure and initialize the value. If closure fails, returns the error. Returns reference to the value.

Source

pub fn try_from_iter<I>(&self, iter: I) -> Result<S, (S, Option<T>)>
where I: IntoIterator<Item = T>,

Allocates memory for an array and initializes it with values from iterator. Uses iterator hints to allocate memory. If iterator yields more values than allocated array can hold, grows allocation and moves next values to extended array. Repeats until iterator is exhausted. Works best on iterators that report accurate upper size hint. Grows allocated memory potentially reducing number of allocations and copies. If allocation fails, returns slice of values emplaced so far. And one element that was taken from iterator and not emplaced.

Source

pub fn from_iter<I>(&self, iter: I) -> S
where I: Iterator<Item = T>,

Allocates memory for an array and initializes it with values from iterator. Uses iterator hints to allocate memory. If iterator yields more values than allocated array can hold, grows allocation and moves next values to extended array. Repeats until iterator is exhausted. Works best on iterators that report accurate upper size hint. Grows allocated memory potentially reducing number of allocations and copies. If allocation fails, diverges. Values already emplaced will be dropped. One last value that was taken from iterator and not emplaced is dropped before this method returns.

Auto Trait Implementations§

§

impl<'a, A, T, R, S> Freeze for Emplace<'a, A, T, R, S>

§

impl<'a, A, T, R = &'a mut T, S = &'a mut [T]> !RefUnwindSafe for Emplace<'a, A, T, R, S>

§

impl<'a, A, T, R = &'a mut T, S = &'a mut [T]> !Send for Emplace<'a, A, T, R, S>

§

impl<'a, A, T, R = &'a mut T, S = &'a mut [T]> !Sync for Emplace<'a, A, T, R, S>

§

impl<'a, A, T, R, S> Unpin for Emplace<'a, A, T, R, S>

§

impl<'a, A, T, R = &'a mut T, S = &'a mut [T]> !UnwindSafe for Emplace<'a, A, T, R, S>

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.