brownstone::builder

Struct ArrayBuilder

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

Source

pub const fn new() -> Self

Create a new, empty ArrayBuilder.

Source

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.

Source

pub fn is_empty(&self) -> bool

Returns true if no elements in the array are initialized.

Source

pub fn len(&self) -> usize

Returns the number of initialized elements in the array.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn finish(self) -> [T; N]

Return the fully initialized array.

§Panics

Panics if the array isn’t fully initialized yet.

Source

pub fn finished_slice(&self) -> &[T]

Get the slice of the array that has already been initialized.

Source

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>

Source§

fn clone(&self) -> ArrayBuilder<T, N>

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

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, const N: usize> Debug for ArrayBuilder<T, N>

Source§

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

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

impl<T, const N: usize> Default for ArrayBuilder<T, N>

Source§

fn default() -> Self

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

impl<T, const N: usize> Extend<T> for ArrayBuilder<T, N>

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for ArrayBuilder<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for ArrayBuilder<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for ArrayBuilder<T, N>
where T: Send,

§

impl<T, const N: usize> Sync for ArrayBuilder<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for ArrayBuilder<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for ArrayBuilder<T, N>
where T: UnwindSafe,

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.