# Struct simple_matrix::Matrix[−][src]

`pub struct Matrix<T> { /* fields omitted */ }`

A 2-Dimensional, non-resisable container.

## Methods

### `impl<T> Matrix<T>`[src]

#### `pub fn new(rows: usize, cols: usize) -> Matrix<T> where    T: Default, `[src]

Constructs a new, non-empty Matrix where cells are set to `T::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]

Constructs a new, non-empty Matrix where cells are set from an iterator.
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]

Returns 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]

Returns 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]

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]

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]

Try 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]

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]

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]

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]

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]

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) -> usize`1.0.0[src]

Returns the number of elements the vector can hold without reallocating.

# Examples

```let vec: Vec<i32> = Vec::with_capacity(10);
assert_eq!(vec.capacity(), 10);```

#### ⓘImportant traits for &'a [u8]### Important traits for &'a [u8] `impl<'a> Read for &'a [u8]impl<'a> Write for &'a mut [u8]``pub fn as_slice(&self) -> &[T]`1.7.0[src]

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) -> usize`1.0.0[src]

Returns 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) -> bool`1.0.0[src]

Returns `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]

#### `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]

Creates an iterator from a value. Read more

### `impl<'a, T> IntoIterator for &'a Matrix<T>`[src]

#### `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]

Creates an iterator from a value. Read more

### `impl<'a, T> IntoIterator for &'a mut Matrix<T>`[src]

#### `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]

Creates an iterator from a value. Read more

### `impl<T: Add<Output = T>> Add for Matrix<T>`[src]

#### `type Output = Matrix<T>`

The resulting type after applying the `+` operator.

#### `fn add(self, rhs: Self) -> Self::Output`[src]

Performs the `+` operation.

### `impl<'a: 'b, 'b, T> Add for &'a Matrix<T> where    &'a T: Add<&'b T, Output = T>, `[src]

#### `type Output = Matrix<T>`

The resulting type after applying the `+` operator.

#### `fn add(self, rhs: &'b Matrix<T>) -> Self::Output`[src]

Performs the `+` operation.

### `impl<T: AddAssign> AddAssign for Matrix<T>`[src]

#### `fn add_assign(&mut self, rhs: Self)`[src]

Performs the `+=` operation.

### `impl<'a, T: AddAssign<&'a T>> AddAssign<&'a Matrix<T>> for Matrix<T>`[src]

#### `fn add_assign(&mut self, rhs: &'a Self)`[src]

Performs the `+=` operation.

### `impl<T: Sub<Output = T>> Sub for Matrix<T>`[src]

#### `type Output = Matrix<T>`

The resulting type after applying the `-` operator.

#### `fn sub(self, rhs: Self) -> Self::Output`[src]

Performs the `-` operation.

### `impl<'a: 'b, 'b, T> Sub for &'a Matrix<T> where    &'a T: Sub<&'b T, Output = T>, `[src]

#### `type Output = Matrix<T>`

The resulting type after applying the `-` operator.

#### `fn sub(self, rhs: &'b Matrix<T>) -> Self::Output`[src]

Performs the `-` operation.

### `impl<T: SubAssign> SubAssign for Matrix<T>`[src]

#### `fn sub_assign(&mut self, rhs: Self)`[src]

Performs the `-=` operation.

### `impl<'a, T: SubAssign<&'a T>> SubAssign<&'a Matrix<T>> for Matrix<T>`[src]

#### `fn sub_assign(&mut self, rhs: &'a Self)`[src]

Performs the `-=` operation.

### `impl<T> Mul<Matrix<T>> for Matrix<T> where    T: Mul<Output = T> + AddAssign + Copy, `[src]

#### `type Output = Matrix<T>`

The resulting type after applying the `*` operator.

#### `fn mul(self, rhs: Matrix<T>) -> Self::Output`[src]

Performs the `*` operation.

### `impl<'a, 'b, T: AddAssign> Mul<&'b Matrix<T>> for &'a Matrix<T> where    &'a T: Mul<&'b T, Output = T>, `[src]

#### `type Output = Matrix<T>`

The resulting type after applying the `*` operator.

#### `fn mul(self, rhs: &'b Matrix<T>) -> Self::Output`[src]

Performs the `*` operation.

### `impl<T: Clone> Clone for Matrix<T>`[src]

#### `fn clone(&self) -> Matrix<T>`[src]

Returns a copy of the value. Read more

#### `fn clone_from(&mut self, source: &Self)`1.0.0[src]

Performs copy-assignment from `source`. Read more

### `impl<T: Debug> Debug for Matrix<T>`[src]

#### `fn fmt(&self, f: &mut Formatter) -> Result`[src]

Formats the value using the given formatter. Read more

### `impl<T: Hash> Hash for Matrix<T>`[src]

#### `fn hash<__HT: Hasher>(&self, state: &mut __HT)`[src]

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]

Feeds a slice of this type into the given [`Hasher`]. Read more

### `impl<T: PartialEq> PartialEq for Matrix<T>`[src]

#### `fn eq(&self, other: &Matrix<T>) -> bool`[src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `fn ne(&self, other: &Matrix<T>) -> bool`[src]

This method tests for `!=`.

### `impl<T: PartialOrd> PartialOrd for Matrix<T>`[src]

#### `fn partial_cmp(&self, other: &Matrix<T>) -> Option<Ordering>`[src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `fn lt(&self, other: &Matrix<T>) -> bool`[src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `fn le(&self, other: &Matrix<T>) -> bool`[src]

This 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]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

#### `fn ge(&self, other: &Matrix<T>) -> bool`[src]

This 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]

#### `type Target = Vec<T>`

The resulting type after dereferencing.

#### `fn deref(&self) -> &Self::Target`[src]

Dereferences the value.