Vec2d

Struct Vec2d 

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

Source

pub fn new_with_default(rows: usize, cols: usize) -> Vec2d<T>

Creates a new Vec2d<T> and initializes all the values to T::default().

Source

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.

Source

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>

Source

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.

Source

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.

Source

pub fn insert_col(&mut self, index: usize, data: &[T])

Inserts a column of data before the columns indicated by index.

Source

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

pub fn push_col(&mut self, data: &[T])

Adds a new column of data to the right edge of the array. The length of the slice data must be exactly equal to the height of the array.

Source

pub fn push_row(&mut self, data: &[T])

Adds a row of data at the bottom of the array. The length of the slice data must be exactly equal to the array width or the method will panic.

Source§

impl<T: PartialEq> Vec2d<T>

Source

pub fn contains(&self, val: &T) -> bool

Checks if val is equivalent to any of the elements in the array. Returns true if there is a match, false otherwise.

Source§

impl<T> Vec2d<T>

Source

pub fn new() -> Vec2d<T>

Creates a new Vec2d<T> with no rows, columns, or elements.

Source

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.

Source

pub fn as_ptr(&self) -> *const T

Returns a raw pointer to the underlying vector’s buffer.

Source

pub fn as_vec(&self) -> &Vec<T>

Returns a reference to the underlying vector.

Source

pub fn count(&self) -> usize

Returns the number of elements in the array. Equal to the number of rows times the number of columns.

Source

pub fn count_cols(&self) -> usize

Returns the number of columns of the array.

Source

pub fn count_rows(&self) -> usize

Returns the number of rows of the array.

Source

pub fn size(&self) -> (usize, usize)

Returns the dimensions of the array as a tuple of (row, col).

Trait Implementations§

Source§

impl<T: Clone> Clone for Vec2d<T>

Source§

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

Returns a duplicate 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> Index<usize> for Vec2d<T>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, row: usize) -> &[T]

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for Vec2d<T>

Source§

fn index_mut(&mut self, row: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Vec2d<T>

§

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

§

impl<T> Send for Vec2d<T>
where T: Send,

§

impl<T> Sync for Vec2d<T>
where T: Sync,

§

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

§

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