Struct das_grid::DasGrid [−][src]
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]
impl<T: Copy + Clone> DasGrid<T>[src]pub fn new(width: i32, height: i32, value: T) -> Self where
T: Clone + Copy + Display, [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]
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]
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]
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]
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]
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>
Trait Implementations
impl<'a, T: Copy + Clone> IntoIterator for &'a DasGrid<T>[src]
impl<'a, T: Copy + Clone> IntoIterator for &'a DasGrid<T>[src]Auto Trait Implementations
impl<T> RefUnwindSafe for DasGrid<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for DasGrid<T> where
T: Send,
T: Send,
impl<T> Sync for DasGrid<T> where
T: Sync,
T: Sync,
impl<T> Unpin for DasGrid<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for DasGrid<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more