[][src]Struct nibbler::nibble::Nibble

pub struct Nibble { /* fields omitted */ }

A struct containing 4 boolean values. Each value represents a bit.

  • bit0 = 2^0 (least significant bit)
  • bit1 = 2^1
  • bit2 = 2^2
  • bit3 = 2^3 (most significant bit)

Implementations

impl Nibble[src]

pub fn new(bit0: bool, bit1: bool, bit2: bool, bit3: bool) -> Nibble[src]

Returns a new instance of the nibble struct.

Example Usage:

use nibbler::traits::Nib;
use nibbler::nibble::Nibble;
let mut nib = Nibble::new(false, false, false, false);
assert_eq!(0, nib.into());
nib = Nibble::new(true, false, false, false);
assert_eq!(1, nib.into());
assert_eq!(nib.b0(), true);
assert_eq!(nib.i0(), 1);
nib = Nibble::new(false, true, false, false);
assert_eq!(2, nib.into());
assert_eq!(nib.b0(), false);
assert_eq!(nib.b1(), true);
assert_eq!(nib.i0(), 0);
assert_eq!(nib.i1(), 1);
nib = Nibble::new(false, false, true, false);
assert_eq!(4, nib.into());
assert_eq!(nib.b0(), false);
assert_eq!(nib.b1(), false);
assert_eq!(nib.b2(), true);
assert_eq!(nib.b3(), false);
assert_eq!(nib.i0(), 0);
assert_eq!(nib.i1(), 0);
assert_eq!(nib.i2(), 1);
assert_eq!(nib.i3(), 0);
nib = Nibble::new(false, false, false, true);
assert_eq!(8, nib.into());
assert_eq!(nib.b0(), false);
assert_eq!(nib.b1(), false);
assert_eq!(nib.b2(), false);
assert_eq!(nib.b3(), true);
assert_eq!(nib.i0(), 0);
assert_eq!(nib.i1(), 0);
assert_eq!(nib.i2(), 0);
assert_eq!(nib.i3(), 1);
nib = Nibble::new(true, true, true, true);
assert_eq!(15, nib.into());

Realistically, or pragmatically, using true/false statements to initialize an instance is not doable.

use nibbler::traits::Nib;
use nibbler::nibble::Nibble;
let val: u8 = 15;
let mut nib = Nibble::from(val);
assert_eq!(15, nib.into());
assert_eq!(nib.b0(), true);
assert_eq!(nib.b1(), true);
assert_eq!(nib.b2(), true);
assert_eq!(nib.b3(), true);
assert_eq!(nib.i0(), 1);
assert_eq!(nib.i1(), 1);
assert_eq!(nib.i2(), 1);
assert_eq!(nib.i3(), 1);
let val: u8 = 16;
//nib = Nibble::from(val) // this fails.
// 16 is 2^4, which is 5-bits; a nibble is only 4-bits.
// 15 is the largest 2^3 value possible (4-bits).

Opposed to the core struct here, Nibble, you probably want Nibbles, which will turn any {u, i}{8, 16, 32, 64} into a Vec, and convert back and forth.

Trait Implementations

impl Clone for Nibble[src]

impl Copy for Nibble[src]

impl Debug for Nibble[src]

impl Display for Nibble[src]

impl From<Nibble> for u64[src]

impl From<Nibble> for i64[src]

impl From<Nibble> for u32[src]

impl From<Nibble> for i32[src]

impl From<Nibble> for u16[src]

impl From<Nibble> for i16[src]

impl From<Nibble> for u8[src]

impl From<Nibble> for i8[src]

impl From<i16> for Nibble[src]

impl From<i32> for Nibble[src]

impl From<i64> for Nibble[src]

impl From<i8> for Nibble[src]

impl From<u16> for Nibble[src]

impl From<u32> for Nibble[src]

impl From<u64> for Nibble[src]

impl From<u8> for Nibble[src]

impl Nib for Nibble[src]

fn as_bit_str_le(&self) -> String[src]

Gets the bit string, Little Endian, MSBit on left, LSBit on right.

fn as_bit_str_be(&self) -> String[src]

Gets the bit string, Big Endian, LSBit on left, MSBit on right.

impl PartialEq<Nibble> for Nibble[src]

impl StructuralPartialEq for Nibble[src]

Auto Trait Implementations

impl RefUnwindSafe for Nibble

impl Send for Nibble

impl Sync for Nibble

impl Unpin for Nibble

impl UnwindSafe for Nibble

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> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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.