pub type LiteralType = u64;
Expand description
The LiteralType is used to set the type for literals that appear in RustHDL expressions. Because of how Rust’s type inference currently works, an expression like
let x: Bits<32> = 0xDEADBEEF.into();
let y : Bits<32> = x + 1;
only works if Rust can unambiguously assign a type to the literal (either DEADBEEF
or 1
).
In earlier versions of RustHDL, this required adding a suffix to the literal like 0xDEADBEEF_u32
,
but those suffixes in turn littered the code and made it difficult to read. Now, only one type
of literal is supported LiteralType, which is an alias for u64. As such, any un-suffixed
number is assumed to be at most a 64 bit integer. This does not limit you in any way from
using suffixed literals. You can express, for example, up to 128 bit constants using standard
Rust notation, and using the [to_bits] trait to convert it to a Bits type.
let x: Bits<128> = 0xDEADBEEF_CAFE_1234_u128.to_bits(); // Works!
However, the following will fail, since the From trait is only implemented on LiteralType to make the conversion unambiguous.
let x: Bits<128> = 0xDEADBEEF_CAFE_1234_u128.into(); // Fails to compile, since conversion from [u128] is not defined