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]>,
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]>,
Sourcepub fn try_value(&self, value: T) -> Result<R, T>
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.
Sourcepub fn value(&self, value: T) -> R
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.
Sourcepub fn try_with<F>(&self, f: F) -> Result<R, F>where
F: FnOnce() -> T,
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.
Sourcepub fn with<F>(&self, f: F) -> Rwhere
F: FnOnce() -> T,
pub fn with<F>(&self, f: F) -> Rwhere
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.
Sourcepub fn try_with_fallible<F, E>(&self, f: F) -> Result<R, Result<E, F>>
pub fn try_with_fallible<F, E>(&self, f: F) -> Result<R, Result<E, F>>
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.
Sourcepub fn with_fallible<F, E>(&self, f: F) -> Result<R, E>
pub fn with_fallible<F, E>(&self, f: F) -> Result<R, E>
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.
Sourcepub fn try_from_iter<I>(&self, iter: I) -> Result<S, (S, Option<T>)>where
I: IntoIterator<Item = T>,
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.
Sourcepub fn from_iter<I>(&self, iter: I) -> Swhere
I: Iterator<Item = T>,
pub fn from_iter<I>(&self, iter: I) -> Swhere
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.