collum 0.1.0

A crate for cleanly describing and parsing bit-wide data structures
Documentation
// Let's say we want to parse an unsigned 2-bit value. So we can set up a struct U2, which is
// defined by two booleans (representing a single-bit of data). Deriving the Collum and Sized
// traits gives us all we need to work with the type when interacting with byte-wide slices.

use collum::{BitOffset, BitSlice, Collum};
use collum_derive::{Collum, Sized};

#[derive(Collum, Sized, Debug, PartialEq)]
struct U2(bool, bool);

fn main() {
    assert_eq!(U2::from_bytes(&[1, 2, 3]), Some(U2(false, false)));
    assert_eq!(U2::from_bytes(&[0b11111111, 0]), Some(U2(true, true)));
    assert_eq!(U2::from_bytes(&[0b10000000, 0]), Some(U2(true, false)));

    assert_eq!(
        <[U2; 10]>::from_bytes(&[0b00000001, 0b00000010, 0b00000011]),
        Some([
            U2(false, false),
            U2(false, false),
            U2(false, false),
            U2(false, true),
            U2(false, false),
            U2(false, false),
            U2(false, false),
            U2(true, false),
            U2(false, false),
            U2(false, false)
        ])
    );
    assert_eq!(
        <[U2; 4]>::from_bytes(&[0b11111111]),
        Some([const { U2(true, true) }; 4])
    );
    assert_eq!(<[U2; 5]>::from_bytes(&[0b11000110]), None);
    assert_eq!(
        <[U2; 4]>::from_bytes(&[0b11000110]),
        Some([
            U2(true, true),
            U2(false, false),
            U2(false, true),
            U2(true, false)
        ])
    );

    assert_eq!(
        <[U2; 5]>::take_from_bit_slice((&[0b11000110, 0b10011100]).into()),
        Some((
            [
                U2(true, true),
                U2(false, false),
                U2(false, true),
                U2(true, false),
                U2(true, false)
            ],
            BitSlice::new(&[0b0011100], BitOffset::Bit2)
        ))
    );
}