Crate typebitset

Source
Expand description

§typebitset

Test Status Crate Docs Minimum rustc version

An type-level number and list implementation for Rust.

§Type-level number

Type-level number is available via FromNum<N> (by type) or from_num::<N>() (by value) interface, or directly constructed using Cons, Bit0 and Bit1.

let v1: Cons<Bit1, Cons<Bit0, Bit1>> = from_num::<5>();
let v2: Cons<Bit1, Bit1> = from_num::<3>() ;
let v3: Bit1 = v1 & v2;
println!("v3 = {}", &v3);
let v4: FromNum<7> = v1 | v2;
let v5: <<Bit0 as ShiftRaising>::Output as Push<Bit1>>::Output = Default::default();

All type-level number implements trait Value, which supports some methods to convert between type, value and usize number.

Some operations are supported for type-level number.

use typebitset::{FromNum, from_num, ShiftRaising, ShiftLowering};
let v1 = from_num::<7>();
let v2: FromNum<3> = v1.shift_raising();
println!("v2 = {}", &v2);

§Type-level list

typebitset supports type-level list, which contains type-level numbers. Some operations are implemented on type-level list.

Modules§

list
This module defines RecList.
prelude
rel

Structs§

Bit0
Represents a bitset represented as zero. Only if a bitset equals to Bit0, the bitset means zero. See Value for details.
Bit1
Represents a bitset represented as one. See Value for details.
Cons
Implementation of bitset. See Value

Traits§

Bit
A trait which represents a bit.
Positive
A trait implemented if the bitset is positive (not zero).
Push
Make left shift of the bitset and use give bit as the LSB.
PushAfterMsb
Concat bitset S after the MSB of Self.
ReplaceOnes
Replacing Bit1 in Self with S. S should be Positive.
ShiftLowering
Generate right shift of the bitset.
ShiftRaising
Generate left shift of the bitset.
Value
The main trait represents a bitset.

Functions§

from_num
Generate Value object using const generics.

Type Aliases§

FromNum
Generate Value type for small number N. FromNum<N> is defined where N is in 0..2 ** 7.