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

This struct represents a two-dimensional window into a one-dimensional slice. This is accomplished through taking either a columns parameter, and dividing the size of the slice 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 values = [0u32; 8];
let mut window = Window2D::new_mut(&mut values, 2);
window[0][1] = 1;
window[1][1] = 2;
window[2][1] = 3;
window[3][1] = 4;

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

Implementations§

source§

impl<'b, T> Window2D<&'b mut [T]>

source

pub fn new_mut(raw: &'b mut [T], columns: usize) -> Self

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

Panics

If the length of raw cannot be divided evenly into columns

source

pub fn new_mut_unchecked(raw: &'b mut [T], rows: usize, columns: usize) -> Self

Creates a new Window2D 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 slice.

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

source§

impl<'b, T> Window2D<&'b [T]>

source

pub fn new_ref(raw: &'b [T], columns: usize) -> Self

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

Panics

If the length of raw cannot be divided evenly into columns

source

pub fn new_ref_unchecked(raw: &'b [T], rows: usize, columns: usize) -> Self

Creates a new Window2D 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 slice.

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

Trait Implementations§

source§

impl<T: Debug> Debug for Window2D<T>

source§

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

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

impl<T> Index<(usize, usize)> for Window2D<&[T]>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: (usize, usize)) -> &Self::Output

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

impl<T> Index<(usize, usize)> for Window2D<&mut [T]>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: (usize, usize)) -> &Self::Output

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

impl<T> Index<usize> for Window2D<&[T]>

§

type Output = [T]

The returned type after indexing.
source§

fn index(&self, row: usize) -> &Self::Output

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

impl<T> Index<usize> for Window2D<&mut [T]>

§

type Output = [T]

The returned type after indexing.
source§

fn index(&self, row: usize) -> &Self::Output

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

impl<T> IndexMut<(usize, usize)> for Window2D<&mut [T]>

source§

fn index_mut(&mut self, index: (usize, usize)) -> &mut Self::Output

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

impl<T> IndexMut<usize> for Window2D<&mut [T]>

source§

fn index_mut(&mut self, row: usize) -> &mut Self::Output

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> MapAny for T

source§

fn map<U, F>(self, map_fn: F) -> Uwhere F: Fn(T) -> U,

Takes a closure and calls it with Self, then returns whatever the closure returned.
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.