Module rust_hdl::prelude

source ·
Expand description

! Prelude module defines common symbols to make importing RustHDL easier.

Re-exports

Modules

Macros

Structs

Enums

Constants

Traits

  • The Block trait is required for all circuitry that can be simulated by RustHDL. If you want to be able to simulate a circuit, the corresponding struct must impl Block. Normally, this is done via the #[derive(LogicBlock)] construct, and you will rarely, if ever, need to impl the Block trait yourself.
  • The ToBits trait is used to provide a way to convert Rust standard unsigned types (currently u8, u16, u32, u64, u128) into Bits of different lengths. Note that RustHDL will panic if you attempt to convert an unsigned type into a Bits that is too small to hold the value.

Functions

  • Cast from one bit width to another with truncation or zero padding The bit_cast function allows you to convert from one bit width to another. It handles the different widths in the following simplified manner: - if casting to a narrower bit width, the most significant bits are discarded until the new value fits into the specified bits - if casting to a wider bit width, the most significant bits are padded with zeros until the new value occupies the specified bits This may seem a bit counterintuitive, but it fits logical circuitry behavior. Narrowing is usually done by preserving the least significant bits (so that the carry bits are discarded when adding, for example). Widening is also usually done (for unsigned values) by zero extending the most significant bits. The bit_cast operation does both of these operations depending on the arguments.
  • Convenience function to construct Bits from an unsigned literal Sometimes, you know you will be working with a value that is smaller than 128 bits (the current maximum sized built-in unsigned integer in Rust). In those cases, the bits function can make construction slightly simpler.
  • This is a helper function used to check a Block for connection, loops, and writes to the inputs.
  • Check to see if a circuit is properly connected (no undriven inputs, or multiply-driven outputs). You can call this directly on a circuit of yours if you want to check that it is correctly connected internally.
  • Compute the minimum number of bits to represent a container with t items. This is basically ceil(log2(t)) as a constant (compile time computable) function. You can use it where a const generic (bit width) argument is required.
  • Convert a frequency in Hz to a period in femtoseconds.
  • Update changes to a circuit until it stabilizes

Type Definitions

  • A type alias for a simple bool. You can use them interchangeably.
  • 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

Attribute Macros

Derive Macros