Struct Jagged2Builder

Source
pub struct Jagged2Builder<T> { /* private fields */ }
Expand description

Struct to facilitate building a jagged array row by row.

§Example

use jagged_array::{Jagged2, Jagged2Builder};

let mut builder = Jagged2Builder::new();
builder.extend(&[1, 2]); // push an array/slice
builder.extend((0..2)); // push an iterator (range)
builder.extend(vec![3]); // push and consume a vector

// Finalize the builder into an array.
let array: Jagged2<u32> = builder.into();

assert_eq!(array.len(), 3);
assert_eq!(array.get_row(0), Some(&[1, 2][..]));
assert_eq!(array.get_row(1), Some(&[0, 1][..]));
assert_eq!(array.get_row(2), Some(&[3][..]));

Implementations§

Source§

impl<T> Jagged2Builder<T>

Source

pub fn new() -> Self

Construct a new array builder, defaulted to not holding any rows.

Source

pub fn with_capacity(row_cap: usize, item_cap: usize) -> Self

Construct an empty array builder, but preallocate enough heap space for row_cap rows, and a total of item_cap items stored cumulatively in the array.

Adding more rows/items than specified after using this constructor is not an error; more space will be allocated on demand.

Source

pub fn len(&self) -> usize

Return the number of rows held in the array builder.

Source

pub fn flat_len(&self) -> usize

Return the total number of T held in the array.

Source

pub fn resize(&mut self, new_len: usize)

If new_len < self.len(), the array will be extended with empty rows until it reaches the given length. Otherwise, rows will be truncated from the tail of the array until the length is reached.

§Example
use jagged_array::Jagged2Builder;
let mut builder: Jagged2Builder<u32> = Jagged2Builder::new();
builder.extend(&[1, 2]);
builder.extend(&[3]);
builder.resize(4);
let mut expected: Jagged2Builder<u32> = Jagged2Builder::new();
expected.extend(&[1, 2]);
expected.extend(&[3]);
expected.extend(&[]);
expected.extend(&[]);
assert_eq!(builder, expected);

Trait Implementations§

Source§

impl<T: Clone> Clone for Jagged2Builder<T>

Source§

fn clone(&self) -> Jagged2Builder<T>

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> Debug for Jagged2Builder<T>

Source§

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

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

impl<T> Default for Jagged2Builder<T>

Source§

fn default() -> Self

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

impl<'a, T> Extend<&'a T> for Jagged2Builder<T>
where T: 'a + Copy,

Source§

fn extend<I>(&mut self, row: I)
where I: IntoIterator<Item = &'a T>,

Push a new row into the builder; this also works for array/slice types passed by reference, if T is Copy.

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

impl<T> Extend<T> for Jagged2Builder<T>

Source§

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

Push a new row into the builder

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

impl<T: Hash> Hash for Jagged2Builder<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Into<Jagged2<T>> for Jagged2Builder<T>

Source§

fn into(self) -> Jagged2<T>

Converts this type into the (usually inferred) input type.
Source§

impl<T: PartialEq> PartialEq for Jagged2Builder<T>

Source§

fn eq(&self, other: &Jagged2Builder<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq> Eq for Jagged2Builder<T>

Source§

impl<T> StructuralPartialEq for Jagged2Builder<T>

Auto Trait Implementations§

§

impl<T> Freeze for Jagged2Builder<T>

§

impl<T> RefUnwindSafe for Jagged2Builder<T>
where T: RefUnwindSafe,

§

impl<T> !Send for Jagged2Builder<T>

§

impl<T> !Sync for Jagged2Builder<T>

§

impl<T> Unpin for Jagged2Builder<T>
where T: Unpin,

§

impl<T> UnwindSafe for Jagged2Builder<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<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> 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.