pub struct Bits { /* private fields */ }
Expand description

Bits representation.

Examples

extern crate xor_distance_exercise;

use xor_distance_exercise::bits::Bits;

// Find out bit size of specific integer type.
let size = Bits::bit_size::<i64>();

// Bit representation of `u64` integer.
let mut bit_rep = Bits::new::<u64>();

// Operations on the bit representation.
let bit = bit_rep.get_bit(4);
bit_rep.set_bit(4, true);
bit_rep.set_bit_within_constrains(5, true);
bit_rep.is_bit_decided(4);
let number = bit_rep.form_zero_padded_number::<u64>().unwrap();

Implementations

Create a new representation of Bits.

Examples
extern crate xor_distance_exercise;

use xor_distance_exercise::bits::Bits;

let bit_rep = Bits::new::<u64>;

Return bit size of the type being represented in bits.

Examples
extern crate xor_distance_exercise;

use xor_distance_exercise::bits::Bits;

assert_eq!(8, Bits::bit_size::<u8>());
assert_eq!(32, Bits::bit_size::<u32>());
assert_eq!(64, Bits::bit_size::<u64>());
assert_eq!(64, Bits::bit_size::<i64>());

Get bit value for the index.

Examples
extern crate xor_distance_exercise;

use xor_distance_exercise::bits::Bits;

let bit_rep = Bits::new::<u64>();
let bit = bit_rep.get_bit(4);
Panics

Panics if index is out of range.

Set new bit value for the index.

Examples
extern crate xor_distance_exercise;

use xor_distance_exercise::bits::Bits;

let mut bit_rep = Bits::new::<u64>();
bit_rep.set_bit(4, true);
bit_rep.set_bit(5, false);
Panics

Panics if index is out of range.

Set new bit value complying with constrains, already decided bit value can not be changed.

Returns Ok(()) in case constrains were not violated, Err(&str) otherwise.

Examples
extern crate xor_distance_exercise;

use xor_distance_exercise::bits::Bits;

let mut bit_rep = Bits::new::<u64>();
bit_rep.set_bit_within_constrains(4, true);
Panics

Panics if index is out of range.

Is bit decided already?

Examples
extern crate xor_distance_exercise;

use xor_distance_exercise::bits::Bits;

let bit_rep = Bits::new::<u64>();
bit_rep.is_bit_decided(4);
Panics

Panics if index is out of range.

Form and return a number based on bits representation, pad/fill undecided bits by zeros.

Examples
extern crate xor_distance_exercise;

use xor_distance_exercise::bits::Bits;

let bit_rep = Bits::new::<u64>();
let number = bit_rep.form_zero_padded_number::<u64>().unwrap();

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.