[][src]Struct board::Vec2d

pub struct Vec2d<T: Clone> { /* fields omitted */ }

Implementations

impl<T: Clone> Vec2d<T>[src]

pub fn new(
    default: T,
    width: usize,
    height: usize
) -> Result<Vec2d<T>, Vec2dError>
[src]

Create a new Vec2d

Examples

let board = board::Vec2d::new('a', 2, 3).unwrap();
assert_eq!(board.tiles(), &vec!['a','a','a','a','a','a']);
assert_eq!(board.width(), 2);
assert_eq!(board.height(), 3);

pub fn new_from_vec(input: Vec<T>, width: usize) -> Result<Vec2d<T>, Vec2dError>[src]

Create a new Vec2d from an existing Vec. Moves the original vec into a Vec2d without copying/cloning.

Examples

let vec = vec!['a','b','c','d'];
let board = board::Vec2d::new_from_vec(vec, 2).unwrap();
assert_eq!(board[(1,0)], 'b');
let vec = vec!['a','b','c','d'];
let board = board::Vec2d::new_from_vec(vec, 3);
assert!(board.is_err());

pub fn for_each_tile<F: FnMut(&mut T)>(&mut self, fun: F)[src]

Apply a function to each tile in Vec2d

Examples

let mut board = board::Vec2d::new('a', 2, 3).unwrap();
board.for_each_tile(|tile| *tile = 'b' );
assert_eq!(board.tiles(), &vec!['b','b','b','b','b','b']);

pub fn tiles(&self) -> &Vec<T>[src]

Get a &Vec<Tile> of the Vec2d<Tile>

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

Get the height of the Vec2d

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

Get the width of the Vec2d

pub fn get(&self, x: usize, y: usize) -> Option<&T>[src]

Get an Option<&Tile> at (x, y)

Examples

let mut board = board::Vec2d::new('a', 2, 3).unwrap();
assert_eq!(board.get(0, 0), Some(&'a'));
assert_eq!(board.get(1, 2), Some(&'a'));
assert_eq!(board.get(2, 2), None);

pub fn get_mut(&mut self, x: usize, y: usize) -> Option<&mut T>[src]

Get an Option<&mut Tile> at (x, y)

Examples

let mut board = board::Vec2d::new('a', 2, 3).unwrap();
assert_eq!(board.get_mut(0, 0), Some(&mut 'a'));
assert_eq!(board.get_mut(1, 2), Some(&mut 'a'));
assert_eq!(board.get_mut(2, 2), None);

pub fn get_row(&self, y: usize) -> Option<&[T]>[src]

pub fn get_row_mut(&mut self, y: usize) -> Option<&mut [T]>[src]

pub fn iter_xy(
    &self
) -> impl Iterator<Item = (usize, impl Iterator<Item = usize>)>
[src]

Get an iterator over all (x, y) values: Iterator<Item = (usize, Iterator<Item = usize>)>

Examples

let board = board::Vec2d::new('a', 2, 3).unwrap();
for (x, row) in board.iter_xy() {
    for y in row {
        assert_eq!(board[(x, y)], 'a')
    }
}

pub fn iter_rows(&self) -> impl Iterator<Item = &[T]>[src]

pub fn iter_rows_mut(&mut self) -> impl Iterator<Item = &mut [T]>[src]

pub fn iter_with_pos<'a>(&'a self) -> impl Iterator<Item = (Pos, &T)>[src]

Iterate over: ((x, y), &Tile)

Examples

let board = board::Vec2d::new(&'a', 2, 2).unwrap();
assert!(
    board.clone().iter_with_pos()
    .all(|((x, y), tile)| board[(x, y)] == *tile )
);

pub fn iter_with_pos_mut<'a>(
    &'a mut self
) -> impl Iterator<Item = (Pos, &'a mut T)>
[src]

Iterate over: ((x, y), &mut Tile)

Examples

let board = board::Vec2d::new(&'a', 2, 2).unwrap();
assert!(
    board.clone().iter_with_pos()
    .all(|((x, y), tile)| board[(x, y)] == *tile )
);

pub fn to_vec(self) -> Vec<T>[src]

Consumes self to return the original Vec

Examples

let vec = vec!['a','b','c','d'];
let board = board::Vec2d::new_from_vec(vec.clone(), 2).unwrap();
let new_vec = board.to_vec();
assert_eq!(vec, new_vec);

Trait Implementations

impl<T: Clone> Clone for Vec2d<T>[src]

impl<T: Debug + Clone> Debug for Vec2d<T>[src]

impl<'de, T: Clone> Deserialize<'de> for Vec2d<T> where
    T: Deserialize<'de>, 
[src]

impl<T: Eq + Clone> Eq for Vec2d<T>[src]

impl<T: Hash + Clone> Hash for Vec2d<T>[src]

impl<T: Clone> Index<(usize, usize)> for Vec2d<T>[src]

type Output = T

The returned type after indexing.

impl<T: Clone> IndexMut<(usize, usize)> for Vec2d<T>[src]

impl<T: PartialEq + Clone> PartialEq<Vec2d<T>> for Vec2d<T>[src]

impl<T: Clone> Serialize for Vec2d<T> where
    T: Serialize
[src]

impl<T: Clone> StructuralEq for Vec2d<T>[src]

impl<T: Clone> StructuralPartialEq for Vec2d<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Vec2d<T> where
    T: RefUnwindSafe
[src]

impl<T> Send for Vec2d<T> where
    T: Send
[src]

impl<T> Sync for Vec2d<T> where
    T: Sync
[src]

impl<T> Unpin for Vec2d<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for Vec2d<T> where
    T: UnwindSafe
[src]

Blanket Implementations

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

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

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

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.

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.