Struct toodee::TooDee[][src]

pub struct TooDee<T> { /* fields omitted */ }

Represents a two-dimensional array.

Empty arrays will always have dimensions of zero.

Implementations

impl<T> TooDee<T>[src]

pub fn new(num_cols: usize, num_rows: usize) -> TooDee<T> where
    T: Default + Clone
[src]

Create a new TooDee array of the specified dimensions, and fill it with the type's default value.

Panics

Panics if one of the dimensions is zero but the other is non-zero. This is to enforce the rule that empty arrays have no dimensions.

Examples

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

pub fn init(num_cols: usize, num_rows: usize, init_value: T) -> TooDee<T> where
    T: Clone
[src]

Create a new TooDee array of the specified dimensions, and fill it with an initial value.

Panics

Panics if one of the dimensions is zero but the other is non-zero. This is to enforce the rule that empty arrays have no dimensions.

Examples

use toodee::{TooDee,TooDeeOps};
let toodee = TooDee::init(10, 5, 42u32);
assert_eq!(toodee.num_cols(), 10);
assert_eq!(toodee.num_rows(), 5);
assert_eq!(toodee[0][0], 42);

pub fn capacity(&self) -> usize[src]

Returns the element capacity of the underlying Vec.

Examples

use toodee::TooDee;
let v = vec![42u32; 10];
let toodee : TooDee<u32> = TooDee::from_vec(5, 2, v);
assert!(toodee.capacity() >= 10);

pub fn with_capacity(capacity: usize) -> TooDee<T>[src]

Constructs a new, empty TooDee<T> with the specified element capacity.

Examples

use toodee::TooDee;
let toodee : TooDee<u32> = TooDee::with_capacity(50);
assert!(toodee.capacity() >= 50);

pub fn reserve_exact(&mut self, capacity: usize)[src]

Reserves the minimum capacity for at least additional more elements to be inserted into the TooDee<T>.

Examples

use toodee::TooDee;
let mut toodee : TooDee<u32> = TooDee::default();
toodee.reserve_exact(50);
assert_eq!(toodee.capacity(), 50);

pub fn reserve(&mut self, capacity: usize)[src]

Reserves capacity for at least additional more elements to be inserted in the given TooDee<T>.

Examples

use toodee::TooDee;
let mut toodee : TooDee<u32> = TooDee::default();
toodee.reserve(50);
assert!(toodee.capacity() >= 50);

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the underlying vector as much as possible.

Examples

use toodee::TooDee;
let mut toodee : TooDee<u32> = TooDee::with_capacity(50);
toodee.shrink_to_fit();
assert_eq!(toodee.capacity(), 0);

pub fn from_vec(num_cols: usize, num_rows: usize, v: Vec<T>) -> TooDee<T>[src]

Create a new TooDee array using the provided vector. The vector's length must match the dimensions of the array.

Panics

Panics if one of the dimensions is zero but the other is non-zero. This is to enforce the rule that empty arrays have no dimensions.

Examples

use toodee::{TooDee,TooDeeOps};
let v = vec![42u32; 10];
let mut toodee : TooDee<u32> = TooDee::from_vec(5, 2, v);
assert_eq!(toodee.num_cols(), 5);
assert_eq!(toodee.num_rows(), 2);
assert_eq!(toodee[0][0], 42);

pub fn from_box(num_cols: usize, num_rows: usize, b: Box<[T]>) -> TooDee<T>[src]

Create a new TooDee array using the provided boxed slice. The slice's length must match the dimensions of the array.

Examples

use toodee::{TooDee,TooDeeOps};
let v = vec![42u32; 10];
let mut toodee : TooDee<u32> = TooDee::from_box(5, 2, v.into_boxed_slice());
assert_eq!(toodee.num_cols(), 5);
assert_eq!(toodee.num_rows(), 2);
assert_eq!(toodee[0][0], 42);

pub fn data(&self) -> &[T][src]

Returns a reference to the raw array data

Examples

use toodee::{TooDee,TooDeeOps};
let v = vec![42u32; 10];
let mut toodee : TooDee<u32> = TooDee::from_vec(5, 2, v);
assert_eq!(toodee.data()[0], 42);

pub fn data_mut(&mut self) -> &mut [T][src]

Returns a mutable reference to the raw array data

Examples

use toodee::{TooDee,TooDeeOps};
let v = vec![42u32; 10];
let mut toodee : TooDee<u32> = TooDee::from_vec(5, 2, v);
assert_eq!(toodee.data_mut()[0], 42);

pub fn clear(&mut self)[src]

Clears the array, removing all values and zeroing the number of columns and rows.

Note that this method has no effect on the allocated capacity of the array.

Examples

use toodee::{TooDee,TooDeeOps};
let v = vec![42u32; 10];
let mut toodee : TooDee<u32> = TooDee::from_vec(5, 2, v);
toodee.clear();
assert_eq!(toodee.num_cols(), 0);
assert_eq!(toodee.num_rows(), 0);
assert!(toodee.capacity() >= 10);

pub fn pop_row(&mut self) -> Option<DrainRow<'_, T>>[src]

Removes the last row from the array and returns it as a Drain, or None if it is empty.

Examples

use toodee::{TooDee,TooDeeOps};
let v = vec![42u32; 15];
let mut toodee : TooDee<u32> = TooDee::from_vec(5, 3, v);
{
   let drain = toodee.pop_row().unwrap();
   assert_eq!(drain.len(), 5);
}
assert_eq!(toodee.num_cols(), 5);
assert_eq!(toodee.num_rows(), 2);

pub fn push_row<I>(&mut self, data: impl IntoIterator<Item = T, IntoIter = I>) where
    I: Iterator<Item = T> + ExactSizeIterator
[src]

Appends a new row to the array.

Panics

Panics if the data's length doesn't match the length of existing rows (if any).

pub fn insert_row<I>(
    &mut self,
    index: usize,
    data: impl IntoIterator<Item = T, IntoIter = I>
) where
    I: Iterator<Item = T> + ExactSizeIterator
[src]

Inserts new data into the array at the specified row

Panics

Panics if the data's length doesn't match the length of existing rows (if any).

pub fn remove_row(&mut self, index: usize) -> DrainRow<'_, T>[src]

Removes the specified row from the array and returns it as a Drain

Panics

Panics if the specified row index is out of bounds.

Examples

use toodee::{TooDee,TooDeeOps};
let v = vec![42u32; 15];
let mut toodee : TooDee<u32> = TooDee::from_vec(5, 3, v);
{
   let drain = toodee.remove_row(1);
   assert_eq!(drain.len(), 5);
}
assert_eq!(toodee.num_cols(), 5);
assert_eq!(toodee.num_rows(), 2);

pub fn pop_col(&mut self) -> Option<DrainCol<'_, T>>[src]

Removes the last column from the array and returns it as a Drain, or None if it is empty.

Examples

use toodee::{TooDee,TooDeeOps};
let v = vec![42u32; 15];
let mut toodee : TooDee<u32> = TooDee::from_vec(5, 3, v);
{
   let drain = toodee.pop_col().unwrap();
   assert_eq!(drain.len(), 3);
}
assert_eq!(toodee.num_cols(), 4);
assert_eq!(toodee.num_rows(), 3);

pub fn push_col<I>(&mut self, data: impl IntoIterator<Item = T, IntoIter = I>) where
    I: Iterator<Item = T> + ExactSizeIterator + DoubleEndedIterator
[src]

Appends a new column to the array.

Panics

Panics if the data's length doesn't match the length of existing rows (if any).

pub fn remove_col(&mut self, index: usize) -> DrainCol<'_, T>

Notable traits for DrainCol<'_, T>

impl<T> Iterator for DrainCol<'_, T> type Item = T;
[src]

Removes the specified column from the array and returns it as a Drain

Panics

Panics if the specified column index is out of bounds.

Examples

use toodee::{TooDee,TooDeeOps};
let v = vec![42u32; 15];
let mut toodee : TooDee<u32> = TooDee::from_vec(5, 3, v);
{
   let drain = toodee.remove_col(1);
   assert_eq!(drain.len(), 3);
}
assert_eq!(toodee.num_cols(), 4);
assert_eq!(toodee.num_rows(), 3);

pub fn insert_col<I>(
    &mut self,
    index: usize,
    data: impl IntoIterator<Item = T, IntoIter = I>
) where
    I: Iterator<Item = T> + ExactSizeIterator + DoubleEndedIterator
[src]

Inserts new data into the array at the specified col.

Panics

Panics if the data's length doesn't match the length of existing columns (if any).

Trait Implementations

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

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

impl<T> AsRef<Vec<T, Global>> for TooDee<T>[src]

We can allow immutable access to the underlying Vec, mut not mutable access because that could lead to changes in the Vec's length.

impl<T: Clone> Clone for TooDee<T>[src]

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

impl<T> Debug for TooDee<T> where
    T: Debug
[src]

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

Custom Default implementation because T does not need to implement Default. See rust issue #26925

fn default() -> Self[src]

Examples

use toodee::TooDee;
struct Abc { }
let toodee : TooDee<Abc> = TooDee::default();

impl<T: Eq> Eq for TooDee<T>[src]

impl<T> From<TooDeeView<'_, T>> for TooDee<T> where
    T: Clone
[src]

impl<T> From<TooDeeViewMut<'_, T>> for TooDee<T> where
    T: Clone
[src]

impl<T: Hash> Hash for TooDee<T>[src]

impl<T> Index<(usize, usize)> for TooDee<T>[src]

type Output = T

The returned type after indexing.

fn index(&self, coord: Coordinate) -> &Self::Output[src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let toodee : TooDee<u32> = TooDee::new(10, 5);
assert_eq!(toodee[(1,3)], 0);

impl<T> Index<usize> for TooDee<T>[src]

type Output = [T]

The returned type after indexing.

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

Examples

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

impl<T> IndexMut<(usize, usize)> for TooDee<T>[src]

fn index_mut(&mut self, coord: Coordinate) -> &mut Self::Output[src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let toodee : TooDee<u32> = TooDee::new(10, 5);
assert_eq!(toodee[(1,3)], 0);

impl<T> IndexMut<usize> for TooDee<T>[src]

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

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let mut toodee : TooDee<u32> = TooDee::new(10, 5);
let mut row = &mut toodee[3];
row[0] = 42;

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

Use Vec's IntoIter for performance reasons.

TODO: return type that implements TooDeeIterator

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIterTooDee<T>

Which kind of iterator are we turning this into?

impl<'a, T> IntoIterator for &'a TooDee<T>[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Cells<'a, T>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Cells is the preferred iterator type here, because it implements TooDeeIterator

impl<'a, T> IntoIterator for &'a mut TooDee<T>[src]

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = CellsMut<'a, T>

CellsMut is the preferred iterator type here, because it implements TooDeeIterator

impl<T: PartialEq> PartialEq<TooDee<T>> for TooDee<T>[src]

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

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

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

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

fn view_mut(
    &mut self,
    start: Coordinate,
    end: Coordinate
) -> TooDeeViewMut<'_, T>
[src]

Examples

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

fn rows_mut(&mut self) -> RowsMut<'_, T>

Notable traits for RowsMut<'a, T>

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

Examples

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

fn col_mut(&mut self, col: usize) -> ColMut<'_, T>

Notable traits for ColMut<'a, T>

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

Examples

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

fn fill(&mut self, fill: T) where
    T: Clone
[src]

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let mut toodee : TooDee<u32> = TooDee::new(10, 5);
toodee.fill(42);
assert_eq!(toodee[1][1], 42);

fn swap_rows(&mut self, r1: usize, r2: usize)[src]

Swap/exchange the data between two rows.

Panics

Panics if either row index is out of bounds.

Examples

use toodee::{TooDee,TooDeeOps,TooDeeOpsMut};
let mut toodee : TooDee<u32> = TooDee::init(10, 5, 42u32);
toodee[0].iter_mut().for_each(|v| *v = 1);
assert_eq!(toodee[(0, 2)], 42);
toodee.swap_rows(0, 2);
assert_eq!(toodee[(0, 2)], 1);

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

Examples

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

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

Examples

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

Auto Trait Implementations

impl<T> Send for TooDee<T> where
    T: Send
[src]

impl<T> Sync for TooDee<T> where
    T: Sync
[src]

impl<T> Unpin for TooDee<T> where
    T: Unpin
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.