[][src]Struct bitmatrix::BitMatrix

pub struct BitMatrix { /* fields omitted */ }

A matrix of bits.

Access can be done through the Index<usize>, Index<(usize, usize)> and IndexMut<usize> traits. As the IndexMut trait is incompatible with proxies, a set method is also provided.

If the serde_support feature is enabled, this type implements serde's Serialize and Deserialize traits.

Implementations

impl BitMatrix[src]

pub fn new(height: usize, width: usize) -> Self[src]

Create a BitMatrix with the given size. All bits are initialized to false.

let matrix = BitMatrix::new(5, 10);

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

Get the matrix height.

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

Get the matrix width.

pub fn iter(&self) -> Iter<'_, Lsb0, usize>[src]

Iterate over all bits in the matrix.

let mut matrix = BitMatrix::new(2, 2);
matrix.set((0,1), true);
matrix.set((1,0), true);
let mut iter = matrix.iter();
assert_eq!(iter.next(), Some(&false));
assert_eq!(iter.next(), Some(&true));
assert_eq!(iter.next(), Some(&true));
assert_eq!(iter.next(), Some(&false));
assert_eq!(iter.next(), None);

pub fn iter_mut(&mut self) -> IterMut<'_, Lsb0, usize>[src]

Iterate over all bits in the matrix.

let mut matrix = BitMatrix::new(2, 2);
let mut iter = matrix.iter_mut();
if let Some(bit) = iter.next() {
	bit.set(true);
}
assert_eq!(matrix[(0,0)], true);

pub fn rows(&self) -> ChunksExact<'_, Lsb0, usize>[src]

An iterator to the matrix rows. Returns an iterator over BitSlices.

pub fn rows_mut(&mut self) -> ChunksExactMut<'_, Lsb0, usize>[src]

A mutable iterator to the matrix rows. Returns a mutable iterator over BitSlices.

pub fn set(&mut self, (i, j): (usize, usize), value: bool)[src]

Set a given bit in the matrix. This method is necessary because IndexMut is incompatible with proxies.

let mut matrix = BitMatrix::new(3, 11);
matrix.set((1,2), true);
assert_eq!(matrix[(1,2)], true);

Panics

Panics if i or j are out of bounds.

pub fn set_all(&mut self, value: bool)[src]

Set all bits in the matrix.

use std::convert::identity;
let mut matrix = BitMatrix::new(3, 11);
matrix.set_all(true);
assert!(matrix.iter().copied().all(identity));

Trait Implementations

impl Clone for BitMatrix[src]

impl Debug for BitMatrix[src]

impl<'de> Deserialize<'de> for BitMatrix[src]

impl Eq for BitMatrix[src]

impl Hash for BitMatrix[src]

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

type Output = bool

The returned type after indexing.

impl Index<usize> for BitMatrix[src]

type Output = BitSlice

The returned type after indexing.

impl IndexMut<usize> for BitMatrix[src]

impl PartialEq<BitMatrix> for BitMatrix[src]

impl Serialize for BitMatrix[src]

impl StructuralEq for BitMatrix[src]

impl StructuralPartialEq for BitMatrix[src]

Auto Trait Implementations

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> Conv for T

impl<T> Conv for T

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> FmtForward for T

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

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

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

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.