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

This struct represents a two-dimensional window into a one-dimensional Vec. This is accomplished through taking either a columns parameter, and dividing the size of the Vec evenly into rows based on its length, or by taking rows and columns directly, trusting that the caller provided correct values. The latter option provides a zero-cost abstraction.

Example

let mut window = Vec2D::from(vec![0u32; 8], 2);
window[0][1] = 1;
window[1][1] = 2;
window[2][1] = 3;
window[3][1] = 4;

let values = window.into_inner();

assert_eq!(values, [0, 1, 0, 2, 0, 3, 0, 4]);

Implementations

Creates a new Vec2D with rows divided into columns length (i.e., w[rows][columns]) placing the result of func in each respective entry.

Panics

If rows * columns > usize::MAX.

Examples
let v = Vec2D::new_with(2, 2, |y, x| 100 * y + 10 * x);
let values = v.into_inner();

assert_eq!(values, [0, 10, 100, 110]);

Creates a new Vec2D with rows divided into columns length. (I.e., w[rows][columns])

Panics

If the length of raw cannot be divided evenly into columns

Creates a new Vec2D divided into rows number of slices with columns entries each.

Providing incorrect values for rows and columns will most likely lead to run-time panics due to indexing outside the range of the Vec.

Using this constructor gives you an essentially zero-cost abstraction.

Unwraps this Vec2D<T>, returning the underlying Vec.

Creates a new Vec2D with rows divided into columns length (i.e., w[rows][columns]) with T::default() in every entry.

Panics

If rows * columns > usize::MAX.

Trait Implementations

Formats the value using the given formatter. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

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

Returns the argument unchanged.

Calls U::from(self).

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

Takes a closure and calls it with Self, then returns whatever the closure returned. 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.