[−][src]Trait toodee::TooDeeOps
Defines operations common to both TooDee
and TooDeeView
. Default implementations are provided
where possible/practical.
Required methods
fn num_cols(&self) -> usize
The number of columns in the area represented by this object.
fn num_rows(&self) -> usize
The number of rows in the area represented by this object.
fn bounds(&self) -> (Coordinate, Coordinate)
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>
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>ⓘ
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>ⓘ
Returns an iterator over a single column.
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]
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
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
fn size(&self) -> (usize, usize)
Returns the size/dimensions of the current object.
fn is_empty(&self) -> bool
Returns true
if the array contains no elements.
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
impl<'a, T> TooDeeOps<T> for TooDeeView<'a, T>
[src]
fn num_cols(&self) -> usize
[src]
fn num_rows(&self) -> usize
[src]
fn bounds(&self) -> (Coordinate, Coordinate)
[src]
fn view(&self, start: Coordinate, end: Coordinate) -> TooDeeView<'_, T>
[src]
fn rows(&self) -> Rows<'_, T>ⓘ
[src]
fn col(&self, col: usize) -> Col<'_, 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]
fn num_rows(&self) -> usize
[src]
fn num_cols(&self) -> usize
[src]
fn bounds(&self) -> (Coordinate, Coordinate)
[src]
fn view(&self, start: Coordinate, end: Coordinate) -> TooDeeView<'_, T>
[src]
fn rows(&self) -> Rows<'_, T>ⓘ
[src]
fn col(&self, col: usize) -> Col<'_, 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>ⓘ
[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>ⓘ
[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); }