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

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

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

Shortcut for self.size.rect()

Width and height

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.