Trait bittle::prelude::Bits

source ·
pub trait Bits: Sealed {
    type IterOnes<'a>: Iterator<Item = u32>
       where Self: 'a;
    type IterOnesIn<'a, E>: Iterator<Item = u32>
       where Self: 'a,
             E: Endian;
    type IterZeros<'a>: Iterator<Item = u32>
       where Self: 'a;
    type IterZerosIn<'a, E>: Iterator<Item = u32>
       where Self: 'a,
             E: Endian;

Show 21 methods // Required methods fn count_ones(&self) -> u32; fn count_zeros(&self) -> u32; fn bits_capacity(&self) -> u32; fn all_zeros(&self) -> bool; fn all_ones(&self) -> bool; fn test_bit(&self, index: u32) -> bool; fn test_bit_in<E>(&self, index: u32) -> bool where E: Endian; fn iter_ones(&self) -> Self::IterOnes<'_>; fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E> where E: Endian; fn iter_zeros(&self) -> Self::IterZeros<'_>; fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E> where E: Endian; // Provided methods fn test_bit_le(&self, index: u32) -> bool { ... } fn test_bit_be(&self, index: u32) -> bool { ... } fn iter_ones_le(&self) -> Self::IterOnesIn<'_, LittleEndian> { ... } fn iter_ones_be(&self) -> Self::IterOnesIn<'_, BigEndian> { ... } fn iter_zeros_le(&self) -> Self::IterZerosIn<'_, LittleEndian> { ... } fn iter_zeros_be(&self) -> Self::IterZerosIn<'_, BigEndian> { ... } fn join_ones_in<I, E>( &self, iter: I ) -> JoinOnes<Self::IterOnesIn<'_, E>, I::IntoIter> where Self: Sized, I: IntoIterator, E: Endian { ... } fn join_ones<I>(&self, iter: I) -> JoinOnes<Self::IterOnes<'_>, I::IntoIter> where Self: Sized, I: IntoIterator { ... } fn join_ones_le<I>( &self, iter: I ) -> JoinOnes<Self::IterOnesIn<'_, LittleEndian>, I::IntoIter> where Self: Sized, I: IntoIterator { ... } fn join_ones_be<I>( &self, iter: I ) -> JoinOnes<Self::IterOnesIn<'_, BigEndian>, I::IntoIter> where Self: Sized, I: IntoIterator { ... }
}
Expand description

Bitset immutable operations.

This is implemented for primitive types such as:

  • usize, u32, u64, and other signed numbers.
  • Arrays made up of numerical primitives, such as [u32; 32].
  • Slices of numerical primitives, such as &[u32].

Also see the associated sibling traits:

Examples

We can use the iterator of each set to compare bit sets of different kinds. The Bits::iter_ones iterator is guaranteed to iterate elements in the same order:

use bittle::{Bits, BitsMut};

let a: [u64; 2] = bittle::set![111];
let mut b = 0u128;

assert!(!a.iter_ones().eq(b.iter_ones()));
b.set_bit(111);
assert!(a.iter_ones().eq(b.iter_ones()));

Required Associated Types§

source

type IterOnes<'a>: Iterator<Item = u32> where Self: 'a

The iterator over zeros in this bit pattern using DefaultEndian indexing.

See Bits::iter_ones.

source

type IterOnesIn<'a, E>: Iterator<Item = u32> where Self: 'a, E: Endian

The iterator over ones in this bit pattern using custom Endian indexing.

See Bits::iter_ones_in.

source

type IterZeros<'a>: Iterator<Item = u32> where Self: 'a

The iterator over zeros in this bit pattern using DefaultEndian indexing.

See Bits::iter_zeros.

source

type IterZerosIn<'a, E>: Iterator<Item = u32> where Self: 'a, E: Endian

The iterator over zeros in this bit pattern using custom Endian indexing.

See Bits::iter_zeros_in.

Required Methods§

source

fn count_ones(&self) -> u32

Get the number of ones in the set.

Examples
use bittle::{Bits, BitsMut};

let mut a = 0u128;
assert_eq!(a.count_ones(), 0);
a.set_bit(4);
assert_eq!(a.count_ones(), 1);

Using a larger set:

use bittle::{Bits, BitsMut};

let mut a = [0u128, 0];
assert_eq!(a.count_ones(), 0);
a.set_bit(240);
assert_eq!(a.count_ones(), 1);
source

fn count_zeros(&self) -> u32

Get the number of ones in the set.

Examples
use bittle::{Bits, BitsMut};

let mut a = 0u128;
assert_eq!(a.count_zeros(), 128);
a.set_bit(4);
assert_eq!(a.count_zeros(), 127);

Using a larger set:

use bittle::{Bits, BitsMut};

let mut a = [0u128, 0];
assert_eq!(a.count_zeros(), 256);
a.set_bit(240);
assert_eq!(a.count_zeros(), 255);
source

fn bits_capacity(&self) -> u32

Get the capacity of the underlying set.

Examples
use bittle::Bits;

let mut set = 0u128;
assert_eq!(set.bits_capacity(), 128);

Using a larger set:

use bittle::Bits;

let mut set = [0u128, 0];
assert_eq!(set.bits_capacity(), 256);
source

fn all_zeros(&self) -> bool

Test if this set is empty, or all zeros.

Examples
use bittle::Bits;

let a: u32 = bittle::set![];
assert!(a.all_zeros());

let a: u32 = bittle::set![1];
assert!(!a.all_zeros());

Using a larger set:

use bittle::Bits;

let a: [u32; 2] = bittle::set![];
assert!(a.all_zeros());

let a: [u32; 2] = bittle::set![55];
assert!(!a.all_zeros());
source

fn all_ones(&self) -> bool

Test if bit set is full, or all ones.

Examples
use bittle::{Bits, BitsMut, BitsOwned};

let mut set = u128::ones();
assert!(set.all_ones());
set.clear_bit(4);
assert!(!set.all_ones());
source

fn test_bit(&self, index: u32) -> bool

Test if the given bit is set using DefaultEndian indexing.

Indexes which are out of bounds will wrap around in the bitset.

Examples
use bittle::Bits;

let a: u32 = bittle::set![];
assert!(!a.test_bit(32));

let a: u32 = bittle::set![32];
assert!(a.test_bit(32));

Using a larger set:

use bittle::Bits;

let a: [u32; 2] = bittle::set![];
assert!(!a.test_bit(55));

let a: [u32; 2] = bittle::set![55];
assert!(a.test_bit(55));
source

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

Test if the given bit is set using custom Endian indexing.

Indexes which are out of bounds will wrap around in the bitset.

Examples
use bittle::{Bits, LittleEndian};

let a: u32 = bittle::set_le![];
assert!(!a.test_bit_in::<LittleEndian>(32));

let a: u32 = bittle::set_le![32];
assert!(a.test_bit_in::<LittleEndian>(32));

Using a larger set:

use bittle::{Bits, LittleEndian};

let a: [u32; 2] = bittle::set_le![];
assert!(!a.test_bit_in::<LittleEndian>(55));

let a: [u32; 2] = bittle::set_le![55];
assert!(a.test_bit_in::<LittleEndian>(55));
source

fn iter_ones(&self) -> Self::IterOnes<'_>

Construct an iterator over ones in the bit set using DefaultEndian indexing.

Will iterate through elements from smallest to largest index.

Examples
use bittle::Bits;

let set: u128 = bittle::set![3, 7];
assert!(set.iter_ones().eq([3, 7]));

A larger bit set:

use bittle::Bits;

let set: [u32; 4] = bittle::set![4, 67, 71, 127];
assert!(set.iter_ones().eq([4, 67, 71, 127]));
assert!(set.iter_ones().rev().eq([127, 71, 67, 4]));
source

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

Construct an iterator over ones in the bit set.

Will iterate through elements from smallest to largest index.

Examples
use bittle::{Bits, LittleEndian};

let set: u128 = bittle::set_le![3, 7];
assert!(set.iter_ones_in::<LittleEndian>().eq([3, 7]));

A larger bit set:

use bittle::{Bits, LittleEndian};

let set: [u32; 4] = bittle::set_le![4, 67, 71];
assert!(set.iter_ones_in::<LittleEndian>().eq([4, 67, 71]));
source

fn iter_zeros(&self) -> Self::IterZeros<'_>

Construct an iterator over zeros in the bit set using DefaultEndian indexing.

Will iterate through elements from smallest to largest index.

Examples
use bittle::Bits;

let set: u8 = bittle::set![3, 7];
assert!(set.iter_zeros().eq([0, 1, 2, 4, 5, 6]));

A larger bit set:

use bittle::Bits;

let set: [u8; 2] = bittle::set![3, 7, 13, 14, 15];
assert!(set.iter_zeros().eq([0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12]));
assert!(set.iter_zeros().rev().eq([12, 11, 10, 9, 8, 6, 5, 4, 2, 1, 0]));
source

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

Construct an iterator over zeros in the bit set.

Will iterate through elements from smallest to largest index.

Examples
use bittle::{Bits, LittleEndian};

let set: u8 = bittle::set_le![3, 7];
assert!(set.iter_zeros_in::<LittleEndian>().eq([0, 1, 2, 4, 5, 6]));

A larger bit set:

use bittle::{Bits, LittleEndian};

let set: [u8; 2] = bittle::set_le![3, 7, 13, 14, 15];
assert!(set.iter_zeros_in::<LittleEndian>().eq([0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12]));

Provided Methods§

source

fn test_bit_le(&self, index: u32) -> bool

Test if the given bit is set using LittleEndian indexing.

Indexes which are out of bounds will wrap around in the bitset.

Examples
use bittle::Bits;

let a: u32 = bittle::set_le![];
assert!(!a.test_bit_le(32));

let a: u32 = bittle::set_le![32];
assert!(a.test_bit_le(32));

Using a larger set:

use bittle::Bits;

let a: [u32; 2] = bittle::set_le![];
assert!(!a.test_bit_le(55));

let a: [u32; 2] = bittle::set_le![55];
assert!(a.test_bit_le(55));
source

fn test_bit_be(&self, index: u32) -> bool

Test if the given bit is set using BigEndian indexing.

Indexes which are out of bounds will wrap around in the bitset.

Examples
use bittle::Bits;

let a: u32 = bittle::set_be![];
assert!(!a.test_bit_be(32));

let a: u32 = bittle::set_be![32];
assert!(a.test_bit_be(32));

Using a larger set:

use bittle::Bits;

let a: [u32; 2] = bittle::set_be![];
assert!(!a.test_bit_be(55));

let a: [u32; 2] = bittle::set_be![55];
assert!(a.test_bit_be(55));
source

fn iter_ones_le(&self) -> Self::IterOnesIn<'_, LittleEndian>

Construct an iterator over ones in the bit set using LittleEndian indexing.

Will iterate through elements from smallest to largest index.

Examples
use bittle::Bits;

let set: u128 = bittle::set_le![3, 7];
assert!(set.iter_ones_le().eq([3, 7]));

A larger bit set:

use bittle::Bits;

let set: [u32; 4] = bittle::set_le![4, 67, 71];
assert!(set.iter_ones_le().eq([4, 67, 71]));
source

fn iter_ones_be(&self) -> Self::IterOnesIn<'_, BigEndian>

Construct an iterator over ones in the bit set using BigEndian indexing.

Will iterate through elements from smallest to largest index.

Examples
use bittle::Bits;

let set: u128 = bittle::set_be![3, 7];
assert!(set.iter_ones_be().eq([3, 7]));

A larger bit set:

use bittle::Bits;

let set: [u32; 4] = bittle::set_be![4, 67, 71];
assert!(set.iter_ones_be().eq([4, 67, 71]));
source

fn iter_zeros_le(&self) -> Self::IterZerosIn<'_, LittleEndian>

Construct an iterator over zeros in the bit set using LittleEndian indexing.

Will iterate through elements from smallest to largest index.

Examples
use bittle::Bits;

let set: u8 = bittle::set_le![3, 7];
assert!(set.iter_zeros_le().eq([0, 1, 2, 4, 5, 6]));

A larger bit set:

use bittle::Bits;

let set: [u8; 2] = bittle::set_le![3, 7, 13, 14, 15];
assert!(set.iter_zeros_le().eq([0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12]));
source

fn iter_zeros_be(&self) -> Self::IterZerosIn<'_, BigEndian>

Construct an iterator over zeros in the bit set using BigEndian indexing.

Will iterate through elements from smallest to largest index.

Examples
use bittle::Bits;

let set: u8 = bittle::set_be![3, 7];
assert!(set.iter_zeros_be().eq([0, 1, 2, 4, 5, 6]));

A larger bit set:

use bittle::Bits;

let set: [u8; 2] = bittle::set_be![3, 7, 13, 14, 15];
assert!(set.iter_zeros_be().eq([0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12]));
source

fn join_ones_in<I, E>( &self, iter: I ) -> JoinOnes<Self::IterOnesIn<'_, E>, I::IntoIter>where Self: Sized, I: IntoIterator, E: Endian,

Join this bit set with an iterator, creating an iterator that only yields the elements which are set to ones using custom Endian indexing.

The underlying iterator is advanced using Iterator::nth as appropriate.

Examples
use bittle::{Bits, LittleEndian};

let mask: u128 = bittle::set_le![0, 1, 3];
let mut values = vec![false, false, false, false];

for value in mask.join_ones_in::<_, LittleEndian>(values.iter_mut()) {
    *value = true;
}

assert_eq!(values, vec![true, true, false, true]);
source

fn join_ones<I>(&self, iter: I) -> JoinOnes<Self::IterOnes<'_>, I::IntoIter>where Self: Sized, I: IntoIterator,

Join this bit set with an iterator, creating an iterator that only yields the elements which are set to ones using DefaultEndian indexing.

The underlying iterator is advanced using Iterator::nth as appropriate.

Examples
use bittle::Bits;

let mask: u128 = bittle::set![0, 1, 3];
let mut values = vec![false, false, false, false];

for value in mask.join_ones(values.iter_mut()) {
    *value = true;
}

assert_eq!(values, vec![true, true, false, true]);
source

fn join_ones_le<I>( &self, iter: I ) -> JoinOnes<Self::IterOnesIn<'_, LittleEndian>, I::IntoIter>where Self: Sized, I: IntoIterator,

Join this bit set with an iterator, creating an iterator that only yields the elements which are set to ones using LittleEndian indexing.

The underlying iterator is advanced using Iterator::nth as appropriate.

Examples
use bittle::Bits;

let mask: u8 = 0b11010000;
let mut values = vec![false, false, false, false];

for value in mask.join_ones_le(values.iter_mut()) {
    *value = true;
}

assert_eq!(values, vec![true, true, false, true]);
source

fn join_ones_be<I>( &self, iter: I ) -> JoinOnes<Self::IterOnesIn<'_, BigEndian>, I::IntoIter>where Self: Sized, I: IntoIterator,

Join this bit set with an iterator, creating an iterator that only yields the elements which are set to ones using BigEndian indexing.

The underlying iterator is advanced using Iterator::nth as appropriate.

Examples
use bittle::Bits;

let mask: u8 = 0b00001011;
let mut values = vec![false, false, false, false];

for value in mask.join_ones_be(values.iter_mut()) {
    *value = true;
}

assert_eq!(values, vec![true, true, false, true]);

Implementations on Foreign Types§

source§

impl Bits for u8

§

type IterOnes<'a> where Self: 'a = IterOnes<u8, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<u8, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<u8, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<u8, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl<T, const N: usize> Bits for [T; N]where T: Eq + BitsOwned,

source§

fn count_ones(&self) -> u32

Count the number of ones in the array.

Examples
use bittle::Bits;

let a: [u8; 2] = bittle::set![4, 11, 14];
assert_eq!(a.count_ones(), 3);
source§

fn count_zeros(&self) -> u32

Count the number of zeros in the array.

Examples
use bittle::Bits;

let a: [u8; 2] = bittle::set![4, 11, 14];
assert_eq!(a.count_zeros(), 13);
source§

fn bits_capacity(&self) -> u32

Get the capacity of the array.

The capacity of a array is determined by its length.

Examples
use bittle::Bits;

let a: [u8; 4] = bittle::set![4, 11, 14];
assert_eq!(a.bits_capacity(), 32);

Also note that the capacity of an array is known at compile-time through BitsOwned::BITS:

use bittle::BitsOwned;

const CAP: u32 = <[u8; 4]>::BITS;
assert_eq!(CAP, 32);
source§

fn all_zeros(&self) -> bool

Test if the array is all zeros.

Examples
use bittle::Bits;

let a: [u8; 2] = bittle::set![];
assert!(a.all_zeros());

let a: [u8; 2] = bittle::set![4, 11, 14];
assert!(!a.all_zeros());
source§

fn all_ones(&self) -> bool

Test if the array is all ones.

Examples
use bittle::Bits;

let a: [u8; 2] = bittle::set![0..16];
assert!(a.all_ones());

let a: [u8; 2] = bittle::set![4, 11, 14];
assert!(!a.all_ones());
source§

fn test_bit(&self, index: u32) -> bool

Test if the given bit is set in the array.

Examples
use bittle::Bits;

let mut a: [u8; 2] = bittle::set![4, 11, 14];
assert!(a.test_bit(4));
source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

Test if the given bit is set in the array.

Examples
use bittle::{Bits, BigEndian};

let mut a: [u8; 2] = bittle::set_be![4, 11, 14];
assert!(a.test_bit_in::<BigEndian>(4));
source§

fn iter_ones(&self) -> Self::IterOnes<'_>

Iterates over all ones in the array using DefaultEndian indexing.

Examples
use bittle::Bits;

let mut a: [u8; 2] = bittle::set![4, 11, 14];
assert!(a.iter_ones().eq([4, 11, 14]));

let a: [u8; 0] = [];
assert!(a.iter_ones().eq([]));
source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

Iterates over all ones in the array using a custom Endian indexing.

Examples
use bittle::{Bits, LittleEndian};

let mut a: [u8; 2] = bittle::set_le![4, 11, 14];
assert!(a.iter_ones_in::<LittleEndian>().eq([4, 11, 14]));
source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

Iterates over all zeros in the array using DefaultEndian indexing.

Examples
use bittle::Bits;

let mut a: [u8; 2] = bittle::set![4, 11, 14];
assert!(a.iter_zeros().eq([0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 15]));

let a: [u8; 0] = [];
assert!(a.iter_zeros().eq([]));
source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

Iterates over all zeros in the array using a custom Endian indexing

Examples
use bittle::{Bits, LittleEndian};

let mut a: [u8; 2] = bittle::set_le![4, 11, 14];
assert!(a.iter_zeros_in::<LittleEndian>().eq([0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 15]));
§

type IterOnes<'a> where Self: 'a = IterOnes<'a, T, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<'a, T, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<'a, T, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<'a, T, E>

source§

impl Bits for i8

§

type IterOnes<'a> where Self: 'a = IterOnes<i8, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<i8, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<i8, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<i8, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl Bits for u32

§

type IterOnes<'a> where Self: 'a = IterOnes<u32, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<u32, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<u32, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<u32, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl Bits for i128

§

type IterOnes<'a> where Self: 'a = IterOnes<i128, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<i128, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<i128, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<i128, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl<T> Bits for &Twhere T: ?Sized + Bits,

§

type IterOnes<'a> where Self: 'a = <T as Bits>::IterOnes<'a>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = <T as Bits>::IterOnesIn<'a, E>

§

type IterZeros<'a> where Self: 'a = <T as Bits>::IterZeros<'a>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = <T as Bits>::IterZerosIn<'a, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl Bits for i64

§

type IterOnes<'a> where Self: 'a = IterOnes<i64, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<i64, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<i64, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<i64, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl Bits for isize

§

type IterOnes<'a> where Self: 'a = IterOnes<isize, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<isize, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<isize, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<isize, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl<T> Bits for &mut Twhere T: ?Sized + Bits,

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = <T as Bits>::IterOnesIn<'a, E>

§

type IterOnes<'a> where Self: 'a = <T as Bits>::IterOnes<'a>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = <T as Bits>::IterZerosIn<'a, E>

§

type IterZeros<'a> where Self: 'a = <T as Bits>::IterZeros<'a>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl Bits for usize

§

type IterOnes<'a> where Self: 'a = IterOnes<usize, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<usize, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<usize, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<usize, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl Bits for u16

§

type IterOnes<'a> where Self: 'a = IterOnes<u16, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<u16, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<u16, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<u16, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl Bits for u64

§

type IterOnes<'a> where Self: 'a = IterOnes<u64, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<u64, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<u64, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<u64, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl<T> Bits for [T]where T: BitsOwned,

source§

fn count_ones(&self) -> u32

Count the number of ones in the slice.

Examples
use bittle::Bits;

let a: [u8; 2] = bittle::set![4, 11, 14];
let a = a.as_slice();
assert_eq!(a.count_ones(), 3);
source§

fn count_zeros(&self) -> u32

Count the number of zeros in the slice.

Examples
use bittle::Bits;

let a: [u8; 2] = bittle::set![4, 11, 14];
let a = a.as_slice();
assert_eq!(a.count_zeros(), 13);
source§

fn bits_capacity(&self) -> u32

Get the capacity of the slice.

The capacity of a slice is determined by its length.

Examples
use bittle::Bits;

let a: [u8; 4] = bittle::set![4, 11, 14];
let a = &a[..2];
assert_eq!(a.bits_capacity(), 16);
source§

fn all_zeros(&self) -> bool

Test if the slice is all zeros.

Examples
use bittle::Bits;

let a: [u8; 2] = bittle::set![];
let a = a.as_slice();
assert!(a.all_zeros());

let a: [u8; 2] = bittle::set![4, 11, 14];
let a = a.as_slice();
assert!(!a.all_zeros());
source§

fn all_ones(&self) -> bool

Test if the slice is all ones.

Examples
use bittle::Bits;

let a: [u8; 2] = bittle::set![0..16];
let a = a.as_slice();
assert!(a.all_ones());

let a: [u8; 2] = bittle::set![4, 11, 14];
let a = a.as_slice();
assert!(!a.all_ones());
source§

fn test_bit(&self, index: u32) -> bool

Test if the given bit is set in the slice.

Examples
use bittle::Bits;

let mut a: [u8; 2] = bittle::set![4, 11, 14];
let a: &[u8] = a.as_slice();
assert!(a.test_bit(4));
source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

Test if the given bit is set in the slice.

Examples
use bittle::{Bits, BigEndian};

let mut a: [u8; 2] = bittle::set_be![4, 11, 14];
let a: &[u8] = a.as_slice();
assert!(a.test_bit_in::<BigEndian>(4));
source§

fn iter_ones(&self) -> Self::IterOnes<'_>

Iterates over all ones in the slice using DefaultEndian indexing.

Examples
use bittle::Bits;

let mut a: [u8; 2] = bittle::set![4, 11, 14];
let a: &[u8] = a.as_slice();
assert!(a.iter_ones().eq([4, 11, 14]));

let a: &[u8] = &[];
assert!(a.iter_ones().eq([]));
source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

Iterates over all ones in the slice using a custom Endian indexing.

Examples
use bittle::{Bits, LittleEndian};

let mut a: [u8; 2] = bittle::set_le![4, 11, 14];
let a: &[u8] = a.as_slice();
assert!(a.iter_ones_in::<LittleEndian>().eq([4, 11, 14]));
source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

Iterates over all zeros in the slice using DefaultEndian indexing.

Examples
use bittle::Bits;

let mut a: [u8; 2] = bittle::set![4, 11, 14];
let a: &[u8] = a.as_slice();
assert!(a.iter_zeros().eq([0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 15]));

let a: &[u8] = &[];
assert!(a.iter_zeros().eq([]));
source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

Iterates over all zeros in the slice using a custom Endian indexing

Examples
use bittle::{Bits, LittleEndian};

let mut a: [u8; 2] = bittle::set_le![4, 11, 14];
let a: &[u8] = a.as_slice();
assert!(a.iter_zeros_in::<LittleEndian>().eq([0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 15]));
§

type IterOnes<'a> where Self: 'a = IterOnes<'a, T, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<'a, T, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<'a, T, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<'a, T, E>

source§

impl Bits for i16

§

type IterOnes<'a> where Self: 'a = IterOnes<i16, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<i16, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<i16, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<i16, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl Bits for i32

§

type IterOnes<'a> where Self: 'a = IterOnes<i32, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<i32, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<i32, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<i32, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

source§

impl Bits for u128

§

type IterOnes<'a> where Self: 'a = IterOnes<u128, BigEndian>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = IterOnes<u128, E>

§

type IterZeros<'a> where Self: 'a = IterZeros<u128, BigEndian>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = IterZeros<u128, E>

source§

fn count_ones(&self) -> u32

source§

fn count_zeros(&self) -> u32

source§

fn bits_capacity(&self) -> u32

source§

fn all_zeros(&self) -> bool

source§

fn all_ones(&self) -> bool

source§

fn test_bit(&self, index: u32) -> bool

source§

fn test_bit_in<E>(&self, index: u32) -> boolwhere E: Endian,

source§

fn iter_ones(&self) -> Self::IterOnes<'_>

source§

fn iter_ones_in<E>(&self) -> Self::IterOnesIn<'_, E>where E: Endian,

source§

fn iter_zeros(&self) -> Self::IterZeros<'_>

source§

fn iter_zeros_in<E>(&self) -> Self::IterZerosIn<'_, E>where E: Endian,

Implementors§

source§

impl<T, U> Bits for Set<T, U>where T: ?Sized + Bits, U: Endian,

§

type IterOnes<'a> where Self: 'a = <T as Bits>::IterOnesIn<'a, U>

§

type IterOnesIn<'a, E> where Self: 'a, E: Endian = <T as Bits>::IterOnesIn<'a, E>

§

type IterZeros<'a> where Self: 'a = <T as Bits>::IterZerosIn<'a, U>

§

type IterZerosIn<'a, E> where Self: 'a, E: Endian = <T as Bits>::IterZerosIn<'a, E>