pub struct Vec2D<T> { /* private fields */ }
Expand description
Container for 2D data
Implementations§
Source§impl<Elem: Clone> Vec2D<Elem>
impl<Elem: Clone> Vec2D<Elem>
Sourcepub fn from_example(size: Size, example: &Elem) -> Vec2D<Elem>
pub fn from_example(size: Size, example: &Elem) -> Vec2D<Elem>
Create a Vec2D with the given size
. All elements are
initialized as copies of the example
element.
let vector = Vec2D::from_example(Size::new(10, 10), &42);
for (_coord, &item) in vector.iter() {
assert_eq!(item, 42);
}
Source§impl<Elem> Vec2D<Elem>
impl<Elem> Vec2D<Elem>
Sourcepub fn from_vec(size: Size, src: Vec<Elem>) -> Option<Vec2D<Elem>>
pub fn from_vec(size: Size, src: Vec<Elem>) -> Option<Vec2D<Elem>>
Create a Vec2D with the given size
. The contents are set to
src
. None is returned if the size
does not match the
length of src
.
Sourcepub fn get(&self, coord: Coord) -> Option<&Elem>
pub fn get(&self, coord: Coord) -> Option<&Elem>
Returns element at the given coord or None
if the coord is
outside the Vec2D
§Example
let v = Vec2D::from_vec (
Size { width: 3, height: 3 },
vec!['a','b','c','d','e','f','g','h','i']
).unwrap();
assert_eq!(v.get (Coord { x: 1, y: 0 }), Some(&'b'));
assert_eq!(v.get (Coord { x: 1, y: 2 }), Some(&'h'));
assert_eq!(v.get (Coord { x: 3, y: 0 }), None);
Sourcepub fn get_mut(&mut self, coord: Coord) -> Option<&mut Elem>
pub fn get_mut(&mut self, coord: Coord) -> Option<&mut Elem>
Returns a mutable reference to the element at the given coord or
None
if the coord is outside the Vec2D
§Example
let mut v = Vec2D::from_vec (
Size { width: 3, height: 3 },
vec!['a','b','c','d','e','f','g','h','i']
).unwrap();
assert_eq!(v.get_mut (Coord { x: 1, y: 0 }), Some(&mut 'b'));
assert_eq!(v.get_mut (Coord { x: 1, y: 2 }), Some(&mut 'h'));
assert_eq!(v.get_mut (Coord { x: 3, y: 0 }), None);
Sourcepub fn rect_iter(&self, rect: Rect) -> Option<RectIter<'_, Elem>>
pub fn rect_iter(&self, rect: Rect) -> Option<RectIter<'_, Elem>>
Create an iterator over a rectangular region of the
Vec2D. None is returned if the given rect
does not fit
entirely within the Vec2D.
Sourcepub fn rect_iter_at(
&self,
rect: Rect,
start: Coord,
) -> Option<RectIter<'_, Elem>>
pub fn rect_iter_at( &self, rect: Rect, start: Coord, ) -> Option<RectIter<'_, Elem>>
Create an iterator over a rectangular region of the Vec2D with
the start
coord. None is returned if the given rect
does
not fit entirely within the Vec2D or if the start
coord is
not within rect
.
Sourcepub fn iter_mut(&mut self) -> RectIterMut<'_, Elem> ⓘ
pub fn iter_mut(&mut self) -> RectIterMut<'_, Elem> ⓘ
Mutable iterater over the entire Vec2D.
Sourcepub fn rect_iter_mut(&mut self, rect: Rect) -> Option<RectIterMut<'_, Elem>>
pub fn rect_iter_mut(&mut self, rect: Rect) -> Option<RectIterMut<'_, Elem>>
Create a mutable iterator over a rectangular region of the
Vec2D. None is returned if the given rect
does not fit
entirely within the Vec2D.
Sourcepub fn rect_iter_mut_at(
&mut self,
rect: Rect,
start: Coord,
) -> Option<RectIterMut<'_, Elem>>
pub fn rect_iter_mut_at( &mut self, rect: Rect, start: Coord, ) -> Option<RectIterMut<'_, Elem>>
Create a mutable iterator over a rectangular region of the
Vec2D with the start
coord. None is returned if the given
rect
does not fit entirely within the Vec2D or if the
start
coord is not within rect
.