Trait toodee::TooDeeOps

source ·
pub trait TooDeeOps<T>: Index<usize, Output = [T]> + Index<Coordinate, Output = T> {
    // Required methods
    fn num_cols(&self) -> usize;
    fn num_rows(&self) -> usize;
    fn view(&self, start: Coordinate, end: Coordinate) -> TooDeeView<'_, T>;
    fn rows(&self) -> Rows<'_, T> ;
    fn col(&self, col: usize) -> Col<'_, T> ;
    unsafe fn get_unchecked_row(&self, row: usize) -> &[T];
    unsafe fn get_unchecked(&self, coord: Coordinate) -> &T;

    // Provided methods
    fn size(&self) -> (usize, usize) { ... }
    fn is_empty(&self) -> bool { ... }
    fn cells(&self) -> Cells<'_, T> { ... }
}
Expand description

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

Required Methods§

source

fn num_cols(&self) -> usize

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

source

fn num_rows(&self) -> usize

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

source

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

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

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

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

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

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

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

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.

source

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

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.

Provided Methods§

source

fn size(&self) -> (usize, usize)

Returns the size/dimensions of the current object.

source

fn is_empty(&self) -> bool

Returns true if the array contains no elements.

source

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

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

Implementors§

source§

impl<'a, T> TooDeeOps<T> for TooDeeView<'a, T>

source§

impl<'a, T> TooDeeOps<T> for TooDeeViewMut<'a, T>

source§

impl<T> TooDeeOps<T> for TooDee<T>