Trait toodee::TooDeeOps[][src]

pub trait TooDeeOps<T>: Index<usize, Output = [T]> + Index<Coordinate, Output = T> {
    fn num_cols(&self) -> usize;
fn num_rows(&self) -> usize;
fn bounds(&self) -> (Coordinate, Coordinate);
fn view(&self, start: Coordinate, end: Coordinate) -> TooDeeView<'_, T>;
fn rows(&self) -> Rows<'_, T>

Notable traits for Rows<'a, T>

impl<'a, T> Iterator for Rows<'a, T> type Item = &'a [T];
;
fn col(&self, col: usize) -> Col<'_, T>

Notable traits for Col<'a, T>

impl<'a, T> Iterator for Col<'a, T> type Item = &'a T;
;
unsafe fn get_unchecked_row(&self, row: usize) -> &[T];
unsafe fn get_unchecked(&self, coord: Coordinate) -> &T; fn size(&self) -> (usize, usize) { ... }
fn is_empty(&self) -> bool { ... }
fn cells(&self) -> Cells<'_, T> { ... } }

Defines operations common to both TooDee and TooDeeView. Default implementations are provided where possible/practical.

Required methods

fn num_cols(&self) -> usize[src]

The number of columns in the area represented by this object.

fn num_rows(&self) -> usize[src]

The number of rows in the area represented by this object.

fn bounds(&self) -> (Coordinate, Coordinate)[src]

Returns the bounds of the object's area within the original TooDee area (views are not nested for now).

fn view(&self, start: Coordinate, end: Coordinate) -> TooDeeView<'_, T>[src]

Returns a view (or subset) of the current area based on the coordinates provided.

Examples

use toodee::{TooDee,TooDeeOps};
let toodee : TooDee<u32> = TooDee::new(10, 5);
let view = toodee.view((1, 1), (9, 4));
assert_eq!(view.num_cols(), 8);
assert_eq!(view.num_rows(), 3);

fn rows(&self) -> Rows<'_, T>

Notable traits for Rows<'a, T>

impl<'a, T> Iterator for Rows<'a, T> type Item = &'a [T];
[src]

Returns an iterator of slices, where each slice represents an entire row.

Examples

use toodee::{TooDee,TooDeeOps};
let toodee : TooDee<u32> = TooDee::init(10, 5, 42u32);
let mut sum = 0u32;
for r in toodee.rows() {
    sum += r.iter().sum::<u32>();
}
assert_eq!(sum, 42*50);

fn col(&self, col: usize) -> Col<'_, T>

Notable traits for Col<'a, T>

impl<'a, T> Iterator for Col<'a, T> type Item = &'a T;
[src]

Returns an iterator over a single column. Note that the Col iterator is indexable.

Examples

use toodee::{TooDee,TooDeeOps};
let toodee : TooDee<u32> = TooDee::init(10, 5, 42u32);
let mut sum = 0u32;
for c in toodee.col(1) {
    sum += c;
}
assert_eq!(sum, 42*5);

unsafe fn get_unchecked_row(&self, row: usize) -> &[T][src]

Returns a row without checking that the row is valid. Generally it's best to use indexing instead, e.g., toodee[row]

Safety

This is generally not recommended, use with caution! Calling this method with an invalid row is [undefined behavior] even if the resulting reference is not used.

unsafe fn get_unchecked(&self, coord: Coordinate) -> &T[src]

Returns a cell without checking that the cell coordinate is valid. Generally it's best to use indexing instead, e.g., toodee[(col, row)]

Safety

This is generally not recommended, use with caution! Calling this method with an invalid coordinate is [undefined behavior] even if the resulting reference is not used.

Loading content...

Provided methods

fn size(&self) -> (usize, usize)[src]

Returns the size/dimensions of the current object.

fn is_empty(&self) -> bool[src]

Returns true if the array contains no elements.

fn cells(&self) -> Cells<'_, T>[src]

Returns an iterator that traverses all cells within the area.

Examples

use toodee::{TooDee,TooDeeOps};
let toodee : TooDee<u32> = TooDee::init(10, 5, 42u32);
let mut sum = toodee.cells().sum::<u32>();
assert_eq!(sum, 42*50);
Loading content...

Implementors

impl<'a, T> TooDeeOps<T> for TooDeeView<'a, T>[src]

unsafe fn get_unchecked_row(&self, row: usize) -> &[T][src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
unsafe {
    let toodee : TooDee<u32> = TooDee::new(10, 5);
    let view = toodee.view((0,0), (10,5));
    let row = view.get_unchecked_row(3);
    assert_eq!(row.len(), 10);
}

unsafe fn get_unchecked(&self, coord: Coordinate) -> &T[src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let toodee : TooDee<u32> = TooDee::new(10, 5);
let view = toodee.view((0,0), (10,5));
unsafe {
    assert_eq!(*view.get_unchecked((1,3)), 0);
}

impl<'a, T> TooDeeOps<T> for TooDeeViewMut<'a, T>[src]

unsafe fn get_unchecked_row(&self, row: usize) -> &[T][src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
unsafe {
    let mut toodee : TooDee<u32> = TooDee::new(10, 5);
    let mut view = toodee.view_mut((0,0), (10,5));
    let row = view.get_unchecked_row(3);
    assert_eq!(row.len(), 10);
}

unsafe fn get_unchecked(&self, coord: Coordinate) -> &T[src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let mut toodee : TooDee<u32> = TooDee::new(10, 5);
let mut view = toodee.view_mut((0,0), (10,5));
unsafe {
    assert_eq!(*view.get_unchecked((1,3)), 0);
}

impl<T> TooDeeOps<T> for TooDee<T>[src]

fn num_cols(&self) -> usize[src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let toodee : TooDee<u32> = TooDee::new(10, 5);
assert_eq!(toodee.num_cols(), 10);

fn num_rows(&self) -> usize[src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let toodee : TooDee<u32> = TooDee::new(10, 5);
assert_eq!(toodee.num_rows(), 5);

fn bounds(&self) -> (Coordinate, Coordinate)[src]

Examples

use toodee::{TooDee,TooDeeOps};
let toodee : TooDee<u32> = TooDee::new(10, 5);
assert_eq!(toodee.bounds(), ((0, 0), (10, 5)));

fn view(&self, start: Coordinate, end: Coordinate) -> TooDeeView<'_, T>[src]

Examples

use toodee::{TooDee,TooDeeOps};
let toodee : TooDee<u32> = TooDee::new(10, 5);
let view = toodee.view((1,2), (8,4));
assert_eq!(view.num_cols(), 7);
assert_eq!(view.num_rows(), 2);

fn rows(&self) -> Rows<'_, T>

Notable traits for Rows<'a, T>

impl<'a, T> Iterator for Rows<'a, T> type Item = &'a [T];
[src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let mut toodee : TooDee<u32> = TooDee::new(10, 5);
let mut rows = toodee.rows();
assert_eq!(rows.len(), 5);
let r0 = rows.next().unwrap();
assert_eq!(r0.len(), 10);

fn col(&self, col: usize) -> Col<'_, T>

Notable traits for Col<'a, T>

impl<'a, T> Iterator for Col<'a, T> type Item = &'a T;
[src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let mut toodee : TooDee<u32> = TooDee::new(10, 5);
let mut col = toodee.col(8);
assert_eq!(col.len(), 5);

unsafe fn get_unchecked_row(&self, row: usize) -> &[T][src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
unsafe {
    let toodee : TooDee<u32> = TooDee::new(10, 5);
    let row = toodee.get_unchecked_row(3);
    assert_eq!(row.len(), 10);
}

unsafe fn get_unchecked(&self, coord: Coordinate) -> &T[src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let toodee : TooDee<u32> = TooDee::new(10, 5);
unsafe {
    assert_eq!(*toodee.get_unchecked((1,3)), 0);
}
Loading content...