Struct Vec2D

Source
pub struct Vec2D<T> { /* private fields */ }
Expand description

Container for 2D data

Implementations§

Source§

impl<Elem: Clone> Vec2D<Elem>

Source

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

pub fn resize(&mut self, new_size: Size, value: Elem)

Resize in-place so that size() is equal to new_size

Source§

impl<Elem> Vec2D<Elem>

Source

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.

Source

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);
Source

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);
Source

pub fn rect(&self) -> Rect

Shortcut for self.size.rect()

Source

pub fn size(&self) -> Size

Width and height

Source

pub fn iter(&self) -> RectIter<'_, Elem>

Iterator over the entire Vec2D.

Source

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.

Source

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.

Source

pub fn iter_mut(&mut self) -> RectIterMut<'_, Elem>

Mutable iterater over the entire Vec2D.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: Clone> Clone for Vec2D<T>

Source§

fn clone(&self) -> Vec2D<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Vec2D<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Hash> Hash for Vec2D<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq> PartialEq for Vec2D<T>

Source§

fn eq(&self, other: &Vec2D<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq> Eq for Vec2D<T>

Source§

impl<T> StructuralPartialEq for Vec2D<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vec2D<T>

§

impl<T> RefUnwindSafe for Vec2D<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vec2D<T>
where T: Send,

§

impl<T> Sync for Vec2D<T>
where T: Sync,

§

impl<T> Unpin for Vec2D<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vec2D<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.