Struct simple_matrix::Matrix [−][src]
pub struct Matrix<T> { /* fields omitted */ }A 2-Dimensional, non-resisable container.
Methods
impl<T> Matrix<T>[src]
impl<T> Matrix<T>pub fn new(rows: usize, cols: usize) -> Matrix<T> where
T: Default, [src]
pub fn new(rows: usize, cols: usize) -> Matrix<T> where
T: Default, Constructs a new, non-empty MatrixT::default.
Use Matrix::from_iter if you want to set the matrix from an iterator.
Panics
Panics if either rows or cols are equal to 0
Examples
let mut mat: Matrix<i32> = Matrix::new(3, 6);
pub fn from_iter(
rows: usize,
cols: usize,
data: impl IntoIterator<Item = T>
) -> Matrix<T>[src]
pub fn from_iter(
rows: usize,
cols: usize,
data: impl IntoIterator<Item = T>
) -> Matrix<T>Constructs a new, non-empty Matrix
The matrix cells are set row by row.
The iterator can be infinite, this method only consume rows * cols
values from the iterator.
Panics
Panics if either rows or cols are equal to 0.
Panics if the iterator does not have rows * cols values
Examples
let mat: Matrix<usize> = Matrix::new(3, 6, 0..); assert_eq!(mat.get(0, 0).unwrap(), 0); assert_eq!(mat.get(0, 1).unwrap(), 1); assert_eq!(mat.get(1, 0).unwrap(), 6);
pub fn rows(&self) -> usize[src]
pub fn rows(&self) -> usizeReturns the number of rows in the matrix.
Examples
let mat: Matrix<usize> = Matrix::new(3, 6, 0..); assert_eq!(mat.rows(), 3);
pub fn cols(&self) -> usize[src]
pub fn cols(&self) -> usizeReturns the number of columns in the matrix.
Examples
let mat: Matrix<usize> = Matrix::new(3, 6, 0..); assert_eq!(mat.cols(), 6);
pub fn get(&self, row: usize, col: usize) -> Option<&T>[src]
pub fn get(&self, row: usize, col: usize) -> Option<&T>Try to get a reference to the value at given row & column.
Returns None if row or col is outside of the matrix.
Examples
let mat: Matrix<usize> = Matrix::new(3, 6, 0..); assert_eq!(mat.get(0, 0).unwrap(), 0); assert_eq!(mat.get(2, 5).unwrap(), 17); assert!(mat.get(10, 2).is_err());
pub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>[src]
pub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>Try to get a mutable reference to the cell at given row & column.
Returns None if row or col is outside of the matrix.
Examples
let mut mat: Matrix<usize> = Matrix::new(3, 6, 0..); assert_eq!(mat.get(0, 0).unwrap(), 0); let cell = mat.get_mut(0, 0).unwrap(); *cell = 5; assert_eq!(mat.get(0, 0).unwrap(), 5);
pub fn set(&mut self, row: usize, col: usize, value: T) -> bool[src]
pub fn set(&mut self, row: usize, col: usize, value: T) -> boolTry to set the cell at given row & column to the given value.
Returns false if row or col is outside of the matrix.
Returns true if the cell has been modified.
Examples
let mut mat: Matrix<usize> = Matrix::new(3, 6, 0..); assert_eq!(mat.get(0, 0).unwrap(), 0); mat.set(0, 0, 5); assert_eq!(mat.get(0, 0).unwrap(), 5);
pub fn get_row(
&self,
row: usize
) -> Option<impl Iterator<Item = &T>>[src]
pub fn get_row(
&self,
row: usize
) -> Option<impl Iterator<Item = &T>>Try to get an iterator of all cells of the requested row.
Returns None if given row is outside of the matrix.
Examples
let mat: Matrix<usize> = Matrix::new(3, 6, 0..); assert_eq!(mat.get_row(1).unwrap(), vec![6, 7, 8, 9, 10, 11]); assert!(mat.get_row(5).is_err());
pub fn get_col(
&self,
col: usize
) -> Option<impl Iterator<Item = &T>>[src]
pub fn get_col(
&self,
col: usize
) -> Option<impl Iterator<Item = &T>>Try to get an iterator of all cells of the requested column.
Returns None if given row is outside of the matrix.
Examples
let mat: Matrix<usize> = Matrix::new(3, 6, 0..); assert_eq!(mat.get_col(1).unwrap(), vec![1, 7, 13]); assert!(mat.get_col(10).is_err());
pub fn transpose(&self) -> Matrix<T> where
T: Clone, [src]
pub fn transpose(&self) -> Matrix<T> where
T: Clone, Take a MxN Matrix and construct the transposed NxM Matrix.
Examples
let mat: Matrix<usize> = Matrix::new(3, 6, 0..); let mat_t = mat.transpose(); assert_eq!(mat.rows(), mat_t.cols()); assert_eq!(mat.cols(), mat_t.rows()); assert_eq!(mat.get(0, 0).unwrap(), mat_t.get(0, 0).unwrap()); assert_eq!(mat.get(1, 2).unwrap(), mat_t.get(2, 1).unwrap());
pub fn apply<F: FnMut(&T)>(&self, func: F)[src]
pub fn apply<F: FnMut(&T)>(&self, func: F)Apply a function to all cells of the matrix.
Cells are provided as immutable references to the function,
if you want to modify the cells, use apply_mut.
Examples
// Get the sum of all cells let mat: Matrix<usize> = Matrix::new(3, 6, 0..); let mut sum = 0; mat.apply(|n| sum += *n); assert_eq!(sum, 153);
pub fn apply_mut<F: FnMut(&mut T)>(&mut self, func: F)[src]
pub fn apply_mut<F: FnMut(&mut T)>(&mut self, func: F)Apply a function to all cells of the matrix.
Cells are provided as mutable references to the function,
and can therefore be modified.
Examples
// Modify all cells with a function let mut mat: Matrix<usize> = Matrix::new(3, 6, 0..); mat.apply_mut(|n| n *= 2); assert_eq!(mat.get(0, 0).unwrap(), 0); assert_eq!(mat.get(0, 1).unwrap(), 2); assert_eq!(mat.get(0, 2).unwrap(), 4);
Methods from Deref<Target = Vec<T>>
pub fn capacity(&self) -> usize1.0.0[src]
pub fn capacity(&self) -> usizeReturns the number of elements the vector can hold without reallocating.
Examples
let vec: Vec<i32> = Vec::with_capacity(10); assert_eq!(vec.capacity(), 10);
pub fn as_slice(&self) -> &[T]1.7.0[src]
pub fn as_slice(&self) -> &[T]Extracts a slice containing the entire vector.
Equivalent to &s[..].
Examples
use std::io::{self, Write}; let buffer = vec![1, 2, 3, 5, 8]; io::sink().write(buffer.as_slice()).unwrap();
pub fn len(&self) -> usize1.0.0[src]
pub fn len(&self) -> usizeReturns the number of elements in the vector, also referred to as its 'length'.
Examples
let a = vec![1, 2, 3]; assert_eq!(a.len(), 3);
pub fn is_empty(&self) -> bool1.0.0[src]
pub fn is_empty(&self) -> boolReturns true if the vector contains no elements.
Examples
let mut v = Vec::new(); assert!(v.is_empty()); v.push(1); assert!(!v.is_empty());
Trait Implementations
impl<T> IntoIterator for Matrix<T>[src]
impl<T> IntoIterator for Matrix<T>type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter[src]
fn into_iter(self) -> Self::IntoIterCreates an iterator from a value. Read more
impl<'a, T> IntoIterator for &'a Matrix<T>[src]
impl<'a, T> IntoIterator for &'a Matrix<T>type Item = &'a T
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter[src]
fn into_iter(self) -> Self::IntoIterCreates an iterator from a value. Read more
impl<'a, T> IntoIterator for &'a mut Matrix<T>[src]
impl<'a, T> IntoIterator for &'a mut Matrix<T>type Item = &'a mut T
The type of the elements being iterated over.
type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter[src]
fn into_iter(self) -> Self::IntoIterCreates an iterator from a value. Read more
impl<T: Add<Output = T>> Add for Matrix<T>[src]
impl<T: Add<Output = T>> Add for Matrix<T>type Output = Matrix<T>
The resulting type after applying the + operator.
fn add(self, rhs: Self) -> Self::Output[src]
fn add(self, rhs: Self) -> Self::OutputPerforms the + operation.
impl<'a: 'b, 'b, T> Add for &'a Matrix<T> where
&'a T: Add<&'b T, Output = T>, [src]
impl<'a: 'b, 'b, T> Add for &'a Matrix<T> where
&'a T: Add<&'b T, Output = T>, type Output = Matrix<T>
The resulting type after applying the + operator.
fn add(self, rhs: &'b Matrix<T>) -> Self::Output[src]
fn add(self, rhs: &'b Matrix<T>) -> Self::OutputPerforms the + operation.
impl<T: AddAssign> AddAssign for Matrix<T>[src]
impl<T: AddAssign> AddAssign for Matrix<T>fn add_assign(&mut self, rhs: Self)[src]
fn add_assign(&mut self, rhs: Self)Performs the += operation.
impl<'a, T: AddAssign<&'a T>> AddAssign<&'a Matrix<T>> for Matrix<T>[src]
impl<'a, T: AddAssign<&'a T>> AddAssign<&'a Matrix<T>> for Matrix<T>fn add_assign(&mut self, rhs: &'a Self)[src]
fn add_assign(&mut self, rhs: &'a Self)Performs the += operation.
impl<T: Sub<Output = T>> Sub for Matrix<T>[src]
impl<T: Sub<Output = T>> Sub for Matrix<T>type Output = Matrix<T>
The resulting type after applying the - operator.
fn sub(self, rhs: Self) -> Self::Output[src]
fn sub(self, rhs: Self) -> Self::OutputPerforms the - operation.
impl<'a: 'b, 'b, T> Sub for &'a Matrix<T> where
&'a T: Sub<&'b T, Output = T>, [src]
impl<'a: 'b, 'b, T> Sub for &'a Matrix<T> where
&'a T: Sub<&'b T, Output = T>, type Output = Matrix<T>
The resulting type after applying the - operator.
fn sub(self, rhs: &'b Matrix<T>) -> Self::Output[src]
fn sub(self, rhs: &'b Matrix<T>) -> Self::OutputPerforms the - operation.
impl<T: SubAssign> SubAssign for Matrix<T>[src]
impl<T: SubAssign> SubAssign for Matrix<T>fn sub_assign(&mut self, rhs: Self)[src]
fn sub_assign(&mut self, rhs: Self)Performs the -= operation.
impl<'a, T: SubAssign<&'a T>> SubAssign<&'a Matrix<T>> for Matrix<T>[src]
impl<'a, T: SubAssign<&'a T>> SubAssign<&'a Matrix<T>> for Matrix<T>fn sub_assign(&mut self, rhs: &'a Self)[src]
fn sub_assign(&mut self, rhs: &'a Self)Performs the -= operation.
impl<T> Mul<Matrix<T>> for Matrix<T> where
T: Mul<Output = T> + AddAssign + Copy, [src]
impl<T> Mul<Matrix<T>> for Matrix<T> where
T: Mul<Output = T> + AddAssign + Copy, type Output = Matrix<T>
The resulting type after applying the * operator.
fn mul(self, rhs: Matrix<T>) -> Self::Output[src]
fn mul(self, rhs: Matrix<T>) -> Self::OutputPerforms the * operation.
impl<'a, 'b, T: AddAssign> Mul<&'b Matrix<T>> for &'a Matrix<T> where
&'a T: Mul<&'b T, Output = T>, [src]
impl<'a, 'b, T: AddAssign> Mul<&'b Matrix<T>> for &'a Matrix<T> where
&'a T: Mul<&'b T, Output = T>, type Output = Matrix<T>
The resulting type after applying the * operator.
fn mul(self, rhs: &'b Matrix<T>) -> Self::Output[src]
fn mul(self, rhs: &'b Matrix<T>) -> Self::OutputPerforms the * operation.
impl<T: Clone> Clone for Matrix<T>[src]
impl<T: Clone> Clone for Matrix<T>fn clone(&self) -> Matrix<T>[src]
fn clone(&self) -> Matrix<T>Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl<T: Debug> Debug for Matrix<T>[src]
impl<T: Debug> Debug for Matrix<T>fn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl<T: Hash> Hash for Matrix<T>[src]
impl<T: Hash> Hash for Matrix<T>fn hash<__HT: Hasher>(&self, state: &mut __HT)[src]
fn hash<__HT: Hasher>(&self, state: &mut __HT)Feeds this value into the given [Hasher]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, Feeds a slice of this type into the given [Hasher]. Read more
impl<T: PartialEq> PartialEq for Matrix<T>[src]
impl<T: PartialEq> PartialEq for Matrix<T>fn eq(&self, other: &Matrix<T>) -> bool[src]
fn eq(&self, other: &Matrix<T>) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Matrix<T>) -> bool[src]
fn ne(&self, other: &Matrix<T>) -> boolThis method tests for !=.
impl<T: Eq> Eq for Matrix<T>[src]
impl<T: Eq> Eq for Matrix<T>impl<T: PartialOrd> PartialOrd for Matrix<T>[src]
impl<T: PartialOrd> PartialOrd for Matrix<T>fn partial_cmp(&self, other: &Matrix<T>) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &Matrix<T>) -> Option<Ordering>This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Matrix<T>) -> bool[src]
fn lt(&self, other: &Matrix<T>) -> boolThis method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Matrix<T>) -> bool[src]
fn le(&self, other: &Matrix<T>) -> boolThis method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, other: &Matrix<T>) -> bool[src]
fn gt(&self, other: &Matrix<T>) -> boolThis method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &Matrix<T>) -> bool[src]
fn ge(&self, other: &Matrix<T>) -> boolThis method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl<T> Deref for Matrix<T>[src]
impl<T> Deref for Matrix<T>