Struct DynamicGrid

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

Dynamic Grid

Implementations§

Source§

impl<T> DynamicGrid<T>
where T: Clone,

Source

pub fn new() -> Self

Constructor, Returns a dynamic grid

Source

pub fn init(row: usize, col: usize, value: T) -> Self

Init a grid of size rows x columns with the given data element

§Arguments
  • row - number of rows
  • col - number columns
  • value - default value
Source

pub fn from_vec(vec: Vec<Vec<T>>) -> Self

Returns a grid from a vector of vector

§Arguments
  • vec - Vector which represent a grid
Source

pub fn rows(&self) -> usize

Returns number of rows of the grid

Source

pub fn row_size(&self, index_row: usize) -> Option<usize>

Returns the size of the row indicate by the index

§Arguments
  • index - rows index
Source

pub fn row_size_unchecked(&self, index_row: usize) -> usize

Returns the size of the row indicate by the index, without bound checking

§Arguments
  • index - rows index
Source

pub fn push(&mut self, value: T) -> (usize, usize)

push value in the last position of last row

  • value - value to push
Source

pub fn push_at_row( &mut self, index_row: usize, value: T, ) -> Option<(usize, usize)>

push value in the last position at row mentioned

§Argument
  • index_row - index of row
  • value - value to push
Source

pub fn insert(&mut self, index_row: usize, index_col: usize, value: T)

insert value at position

§Argument
  • index_row - index of row
  • index_col - index of col
  • value - value to insert
§Panics

Panics if the row and the col index are out of bounds.

Source

pub fn swap( &mut self, first_position: (usize, usize), second_position: (usize, usize), )

swap two element in the grid

§Argument
  • first_position - position of the first element
  • second_position - position of the second element
§Panics

Panics if the row and the col index are out of bounds.

Source

pub fn push_new_row(&mut self, value: T) -> (usize, usize)

push a new empty row

Source

pub fn remove(&mut self)

remove the last value of the last row

Source

pub fn remove_row(&mut self, index_row: usize)

remove the last row

Source

pub unsafe fn get_unchecked(&self, index_row: usize, index_col: usize) -> &T

Returns a reference to an element, without doing bound checking.

§Arguments

index_row - index of row index_col - index of column

§Example
Source

pub unsafe fn get_unchecked_mut( &mut self, index_row: usize, index_col: usize, ) -> &mut T

Return a mutable reference to an element, without doing bound checking.

§Arguments

index_row - index of row index_col - index of column

§Example
Source

pub fn get(&self, index_row: usize, index_col: usize) -> Option<&T>

Returns a reference to an element.

§Arguments

index_row - index of row index_col - index of column

§Example
Source

pub fn get_mut(&mut self, index_row: usize, index_col: usize) -> Option<&mut T>

Returns a reference to an element.

§Arguments

index_row - index of row index_col - index of column

§Example
Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the whole grid, starting from the first row and column.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an mutable iterator over the whole grid that allows modifying each value.

Source

pub fn iter_row(&self, index_row: usize) -> Iter<'_, T>

Returns a row Iterator

§Panics

Panics if the row index is out of bounds.

Source

pub fn iter_row_mut(&mut self, index_row: usize) -> IterMut<'_, T>

Returns a mutable row Iterator

§Panics

Panics if the row index is out of bounds.

Trait Implementations§

Source§

impl<T: Clone> Clone for DynamicGrid<T>

Source§

fn clone(&self) -> DynamicGrid<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: Debug> Debug for DynamicGrid<T>

Source§

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

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

impl<T: Default> Default for DynamicGrid<T>

Source§

fn default() -> DynamicGrid<T>

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

impl<T> Display for DynamicGrid<T>
where T: Clone + ToString,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for DynamicGrid<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for DynamicGrid<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.