Struct vec2d::Vec2D [−][src]
pub struct Vec2D<T> { /* fields omitted */ }
Expand description
Container for 2D data
Implementations
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);
}
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
.
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);
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);
Iterator over the entire Vec2D.
Create an iterator over a rectangular region of the
Vec2D. None is returned if the given rect
does not fit
entirely within the Vec2D.
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
.
pub fn iter_mut(&mut self) -> RectIterMut<'_, Elem>ⓘNotable traits for RectIterMut<'a, Elem>impl<'a, Elem> Iterator for RectIterMut<'a, Elem> type Item = (Coord, &'a mut Elem);
pub fn iter_mut(&mut self) -> RectIterMut<'_, Elem>ⓘNotable traits for RectIterMut<'a, Elem>impl<'a, Elem> Iterator for RectIterMut<'a, Elem> type Item = (Coord, &'a mut Elem);
impl<'a, Elem> Iterator for RectIterMut<'a, Elem> type Item = (Coord, &'a mut Elem);
Mutable iterater over the entire Vec2D.
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.
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
.
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Vec2D<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Vec2D<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more