pub struct ArrayBuilder<T, const N: usize> { /* private fields */ }
Expand description
Low-level builder type for [T; N]
arrays. Uses a
push
+ finish
interface to
build an array 1 element at a time.
The interface provided by this type is fairly low level; most of its methods
are fallible in some way (returning a Result
or panicking on errors).
Consider instead the misuse-resistant
move_builder::ArrayBuilder
, which uses
ownership semantics to provide only infallible operations, or the
build!
macro at the top level of the crate.
Implementations§
Source§impl<T, const N: usize> ArrayBuilder<T, N>
impl<T, const N: usize> ArrayBuilder<T, N>
Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true if every element in the array is initialized. If the
builder is full, the next call to finish
will return the built array.
Sourcepub unsafe fn push_unchecked(&mut self, value: T) -> PushResult
pub unsafe fn push_unchecked(&mut self, value: T) -> PushResult
Add an initialized element to the array, without performing a bounds check.
§Safety
This must only be called when the builder is not full.
Sourcepub fn try_push(&mut self, value: T) -> Result<PushResult, Overflow<T>>
pub fn try_push(&mut self, value: T) -> Result<PushResult, Overflow<T>>
Try to add an initialized element to the array. Returns an error if the
array is already full, or a PushResult
indicating if the array is now full
and can be retrieved via finish
.
Sourcepub fn push(&mut self, value: T) -> PushResult
pub fn push(&mut self, value: T) -> PushResult
Add an initialized element to the array. Returns a PushResult
indicating if the array is now full and can be retrieved via
finish
.
§Panics
Panics if the array is already full.
Sourcepub unsafe fn finish_unchecked(self) -> [T; N]
pub unsafe fn finish_unchecked(self) -> [T; N]
Return the fully initialized array without checking that it’s fully initialized.
§Safety
This must only be called when the builder is full.
Sourcepub fn try_finish(self) -> Result<[T; N], Self>
pub fn try_finish(self) -> Result<[T; N], Self>
Try to return the fully initialized array. Returns the builder if the array isn’t fully initialized yet.
Sourcepub fn finished_slice(&self) -> &[T]
pub fn finished_slice(&self) -> &[T]
Get the slice of the array that has already been initialized.
Sourcepub fn finished_slice_mut(&mut self) -> &mut [T]
pub fn finished_slice_mut(&mut self) -> &mut [T]
Get the mutable slice of the array that has already been initialized.
Trait Implementations§
Source§impl<T: Clone, const N: usize> Clone for ArrayBuilder<T, N>
impl<T: Clone, const N: usize> Clone for ArrayBuilder<T, N>
Source§fn clone(&self) -> ArrayBuilder<T, N>
fn clone(&self) -> ArrayBuilder<T, N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T, const N: usize> Default for ArrayBuilder<T, N>
impl<T, const N: usize> Default for ArrayBuilder<T, N>
Source§impl<T, const N: usize> Extend<T> for ArrayBuilder<T, N>
impl<T, const N: usize> Extend<T> for ArrayBuilder<T, N>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)