Struct das_grid::DasGrid[][src]

pub struct DasGrid<T: Copy + Clone> { /* fields omitted */ }

Stores the grid values and the cells The grid itself representation is a flatten vector which is transformed for 2D representation when called by the user

The cells are internally manage by a Vec<T>

Implementations

impl<T: Copy + Clone> DasGrid<T>[src]

pub fn new(width: i32, height: i32, value: T) -> Self where
    T: Clone + Copy + Display
[src]

Creates a grid of size rows x columns with default value passed on the third parameter For example this will generate a 2x2 grid of value 1:

use DasGrid::Grid;
let grid = Grid::new(2, 2, 1);
assert!(grid.size() == 4);

pub fn set(&mut self, index: (i32, i32), value: &T) -> Result<(), OutOfGridErr> where
    T: Copy
[src]

Sets a given value to the position (x, y)

Be careful if the value is out of the bounds of grid it will return an error with the type of OutOfGridErr

use DasGrid::Grid;
let mut grid = Grid::new(2, 2, 1);
grid.set((0, 0), &1); // Result<(), OutOfGridErr>

pub fn get_mut(&mut self, index: (i32, i32)) -> Result<&mut T, OutOfGridErr>[src]

Gets a give value to the position (x, y) as mutable

Be careful if the value is out of the bounds of grid it will return an error with the type of OutOfGridErr

use DasGrid::Grid;
let grid = Grid::new(2, 2, 1);
let mut v = grid.get_mut((0, 0)); // Result<&T, OutOfGridE

pub fn get(&self, index: (i32, i32)) -> Result<&T, OutOfGridErr>[src]

Gets a give value to the position (x, y)

Be careful if the value is out of the bounds of grid it will return an error with the type of OutOfGridErr

use DasGrid::Grid;
let grid = Grid::new(2, 2, 1);
let v = grid.get((0, 0)); // Result<&T, OutOfGridErr>

pub fn mov(
    &mut self,
    index: (i32, i32),
    dest: (i32, i32)
) -> Result<(), OutOfGridErr>
[src]

Moves a given value from position (x, y) to destiny position (x, y)

Be careful if the value is out of the bounds of grid it will return an error with the type of OutOfGridErr

use DasGrid::Grid;
let mut grid = Grid::new(2, 2, 1);
grid.mov((0, 0), (1, 1)); // Result<(), OutOfGridErr>

pub fn mov_to(
    &mut self,
    index: (i32, i32),
    direction: MoveDirection
) -> Result<(), OutOfGridErr>
[src]

Moves a given value from position (x, y) to another position based on the direction

The directions can be Left, Right, Top, Down:

  • DasGrid::MoveDirection::Left, translates to (-1, 0)
  • DasGrid::MoveDirection::Right, translates to (1, 0)
  • DasGrid::MoveDirection::Top, translates to (0, -1)
  • DasGrid::MoveDirection::Down, translates to (0, 1)

Be careful if the value is out of the bounds of grid it will return an error with the type of OutOfGridErr

use DasGrid::Grid;
let mut grid = Grid::new(2, 2, 1);
grid.mov_to((0, 0), Grid::MoveDirection::Right)); // Result<(), OutOfGridErr>

pub fn size(&self) -> usize[src]

Get the size of grid based on cells length

For instance a 10x10 grid will return the size of 100

use DasGrid::Grid;
let grid = Grid::new(2, 2, 1);
grid.size(); // Equals 4

pub fn width(&self) -> i32[src]

The width of the grid

pub fn height(&self) -> i32[src]

The height of the grid

pub fn enumerate(&self) -> Vec<(i32, i32)>[src]

Returns the grid as a tuple of (x, y)

let grid = Grid::new(2, 2, 1);
for (x, y) in grid.enumerate() {
    println!("x {} y {}", x, y);
}

Trait Implementations

impl<T: Copy + Clone + Display> Debug for DasGrid<T>[src]

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

Formats the value using the given formatter. Read more

impl<T: Copy + Clone> Display for DasGrid<T>[src]

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

Formats the value using the given formatter. Read more

impl<T: Copy + Clone> Index<(i32, i32)> for DasGrid<T>[src]

type Output = T

The returned type after indexing.

fn index(&self, index: (i32, i32)) -> &T[src]

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

impl<T: Copy + Clone> IndexMut<(i32, i32)> for DasGrid<T>[src]

fn index_mut(&mut self, index: (i32, i32)) -> &mut T[src]

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

impl<'a, T: Copy + Clone> IntoIterator for &'a DasGrid<T>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

impl<'a, T: Copy + Clone> IntoIterator for &'a mut DasGrid<T>[src]

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

Auto Trait Implementations

impl<T> RefUnwindSafe for DasGrid<T> where
    T: RefUnwindSafe

impl<T> Send for DasGrid<T> where
    T: Send

impl<T> Sync for DasGrid<T> where
    T: Sync

impl<T> Unpin for DasGrid<T> where
    T: Unpin

impl<T> UnwindSafe for DasGrid<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.