Crate awint_macros[][src]

Expand description

Accompanying procedural macros to awint

use awint_macros::{inlawi_ty, inlawi, inlawi_le, inlawi_be};
// Note: The macros require `InlAwi` to be in scope. This could be from
// `awint_core` or a reexport from `awint`.
use awint_core::InlAwi;

// constructs an `InlAwi` out of a 16 bit negative signed 1, a 16 bit
// binary string, and 8 bit unsigned 42. The total bitwidth is
// 16 + 16 + 8 = 40.
let awi0: inlawi_ty!(40) = inlawi!(-1i16, 0000_0101_0011_1001, 42u8);

// We use `inlawi!` again to show the different components in hexadecimal.
// Note that while the literals are typed in big-endian, the list and
// the way they are concatenated is in little-endian. This matches the
// way Rust array literals (e.g. `[0xffff, 0x539, 0x2a]`) work.
let awi1 = inlawi!(0xffffu16, 0x539u16, 0x2au8);
assert_eq!(awi0, awi1);

// `inlawi_be!` interprets both the literals and list order as big-endian
let awi2 = inlawi_be!(0x2au8, 0x539u16, 0xffffu16);
assert_eq!(awi0, awi2);

// `inlawi!` should be used in most circumstances with one literal
let awi3 = inlawi!(0x2A_0539_FFFFu40);
assert_eq!(awi0, awi3);

// `inlawi_le!` uses little endian for both literals and the component
// order. This macro is intended mainly for plain binary strings
// (e.x. `inlawi_le!(00101, 0011) == inlawi_be!(1100, 10100)`)
let awi4 = inlawi_le!(61uffffx0, 61u935x0, 8ua2x0);
assert_eq!(awi0, awi4);

Macros

inlawi

General construction of an InlAwi. The input should be a comma-separated list of literals that can be parsed by <ExtAwi as FromStr>::from_str. The resulting arbitrary width integers are concatenated together to create one InlAwi at compile time. The individual literals are big-endian (processed how from_str would normally process them), while the component concatenation order is little-endian.

inlawi_be

General construction of an InlAwi. The input should be a comma-separated list of literals that can be parsed by <ExtAwi as FromStr>::from_str. The resulting arbitrary width integers are concatenated together to create one InlAwi at compile time. The individual literals and component concatenation order are both big-endian.

inlawi_le

General construction of an InlAwi. The input should be a comma-separated list of literals that can be parsed by <ExtAwi as FromStr>::from_str. The resulting arbitrary width integers are concatenated together to create one InlAwi at compile time. The individual literals and component concatenation order are both little-endian.

inlawi_ty

Specifies an InlAwi type in terms of its bitwidth as a usize literal.

inlawi_umax

Unsigned-maximum-value construction of an InlAwi. The input should be a usize literal indicating bitwidth.

inlawi_zero

Zero-value construction of an InlAwi. The input should be a usize literal indicating bitwidth.