Crate devela_macros

Source
Expand description

§Conditional compilation

Each form of conditional compilation takes a compilation predicate that evaluates to true or false.

These are the #[compile] and #[compile_attr] attributes and the cif! macro.

They are similar to the #[cfg] and #[cfg_attr] attributes and the cfg! macro, except they use compilation predicates.

There is also the [#[compile_doc]][compile_doc()] macro to conditionally compile documentation blocks depending on predicates.

§Panics

Compilation macros will panic if they encounter an unrecognized predicate. As opposed to configuration macros (cfg!) that return false for unrecognized predicates without signaling an error.

§Compilation predicates

The following compilation predicates are supported:

  • unary:

    • A bare predicate returns true only if it is the true literal.
    • A bare predicate returns false if it’s the false literal or it’s empty.
    • not(): returns true only if the predicate does not evaluate to true.
  • binary:

    • equal(): returns true if both predicates are evaluated as equal.

    • xor(): returns true if only one predicate is true, but not both.

    • eq(): returns true if both predicates are number literals and Left == Right.

    • ne(): returns true if both predicates are number literals and Left != Right.

    • ge(): returns true if both predicates are number literals and Left >= Right.

    • gt(): returns true if both predicates are number literals and Left > Right.

    • le(): returns true if both predicates are number literals and Left <= Right.

    • lt(): returns true if both predicates are number literals and Left < Right.

  • non-binary:

    • any(): returns true if any predicate is true.
    • all(): returns true if all predicates are true.
    • none(): returns true if there is no given predicate.
    • some(): returns true if there is some given predicate.
    • diff(): returns true if any predicate has a different text.
    • same(): returns true if all the predicates have the same text.
    • xany(): returns true if there are any true predicates, but not all.
    • xodd(): returns true if there is an odd number of true predicates.
    • xone(): returns true if there is just one true predicate, but no more.
  • pointer width:

    • pointer_width_eq(width): returns true if current pointer width == the given width.
    • pointer_width_ne(width): returns true if current pointer width != the given width.
    • pointer_width_ge(width): returns true if current pointer width >= the given width.
    • pointer_width_gt(width): returns true if current pointer width > the given width.
    • pointer_width_le(width): returns true if current pointer width <= the given width.
    • pointer_width_lt(width): returns true if current pointer width < the given width.
  • endianness:

    • little_endian(): returns true if current architecture is little-endian.
    • big_endian(): returns true if current architecture is big-endian.

When more than 1 predicate is supported, they are separated by commas.

Macros§

  • cifalloc
    Evaluates to either a true of false literal based on the predicate.
  • Returns the first non-empty argument.
  • enumintalloc
    Generates a unit-only enum with variants associated to a specified range.
  • Generates an expression for accessing a field of a tuple or struct.
  • Returns the total number of identifiers in its input.
  • ident_total_uniquedep_hashbrown or std
    Returns the numbers of both total and unique identifiers in its input.
  • ident_uniquedep_hashbrown or std
    Returns the number of unique identifiers in its input.

Attribute Macros§