pub struct Vec2d<T> { /* private fields */ }Expand description
A two-dimensional array. Unlike a standard vector, Vec2d must maintain a constant
number of elements equal to its number of rows times its number of columns.
Implementations§
Source§impl<T: Default> Vec2d<T>
impl<T: Default> Vec2d<T>
Sourcepub fn new_with_default(rows: usize, cols: usize) -> Vec2d<T>
pub fn new_with_default(rows: usize, cols: usize) -> Vec2d<T>
Creates a new Vec2d<T> and initializes all the values to T::default().
Sourcepub fn add_row_of_default(&mut self)
pub fn add_row_of_default(&mut self)
Adds a new row to the vector and sets all elements of that row to T::default().
If the array is empty, creates a row of one element.
Sourcepub fn add_col_of_default(&mut self)
pub fn add_col_of_default(&mut self)
Adds a new column to the array and sets all elements of the column to T::default().
Source§impl<T: Copy> Vec2d<T>
impl<T: Copy> Vec2d<T>
Sourcepub fn new_with_value(rows: usize, cols: usize, val: T) -> Vec2d<T>
pub fn new_with_value(rows: usize, cols: usize, val: T) -> Vec2d<T>
Creates a new Vec2d<T> and initializes all the values to a copy of val.
Sourcepub fn from(width: usize, arr: &[T]) -> Vec2d<T>
pub fn from(width: usize, arr: &[T]) -> Vec2d<T>
Creates a new Vec2d<T> from an array slice.
The slice must have a length that is divisible by cols in order to fill the new array.
The array is filled left to right, top to bottom.
Sourcepub fn insert_col(&mut self, index: usize, data: &[T])
pub fn insert_col(&mut self, index: usize, data: &[T])
Inserts a column of data before the columns indicated by index.
Sourcepub fn insert_row(&mut self, index: usize, data: &[T])
pub fn insert_row(&mut self, index: usize, data: &[T])
Inserts a row of data before the row indicated by index. If index is 0, calls
push_row(data).
Source§impl<T> Vec2d<T>
impl<T> Vec2d<T>
Sourcepub fn from_fn(
rows: usize,
cols: usize,
initializer: &dyn Fn(usize, usize) -> T,
) -> Vec2d<T>
pub fn from_fn( rows: usize, cols: usize, initializer: &dyn Fn(usize, usize) -> T, ) -> Vec2d<T>
Creates a new Vec2d<T> and initializes its values from initializer,
a passed-in function that takes the current cell index (row and column)
and returns a T.
Sourcepub fn count(&self) -> usize
pub fn count(&self) -> usize
Returns the number of elements in the array. Equal to the number of rows times the number of columns.
Sourcepub fn count_cols(&self) -> usize
pub fn count_cols(&self) -> usize
Returns the number of columns of the array.
Sourcepub fn count_rows(&self) -> usize
pub fn count_rows(&self) -> usize
Returns the number of rows of the array.