13 releases (breaking)

new 0.10.0 Apr 16, 2024
0.9.0 Feb 26, 2024
0.8.0 Jan 16, 2024
0.7.1 Dec 11, 2023
0.3.0 May 9, 2023

#1977 in Procedural macros

Download history 100/week @ 2024-01-01 13/week @ 2024-01-08 103/week @ 2024-01-15 107/week @ 2024-01-22 137/week @ 2024-01-29 188/week @ 2024-02-05 90/week @ 2024-02-12 143/week @ 2024-02-19 282/week @ 2024-02-26 78/week @ 2024-03-04 159/week @ 2024-03-11 104/week @ 2024-03-18 140/week @ 2024-03-25 215/week @ 2024-04-01 15/week @ 2024-04-08 283/week @ 2024-04-15

654 downloads per month
Used in 11 crates (via devela)

MIT/Apache

30KB
419 lines

devela_macros

Crate API MSRV: 1.72.1

Procedural macros for devela.

See the documentation for more information.

Status

This is currently in an experimental stage of development.

License

This project is dual licensed under either MIT or Apache-2.0 at your option.

Contributing

Contributions are welcomed to help refine and improve this library over time. If you notice a bug, have an idea for a new feature, or simply want to suggest improvements to the existing codebase, please get in touch.


lib.rs:

Conditional compilation

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

These are the [#[compile]][compile()] and [#[compile_attr]][compile_attr()] attributes and the [cif!][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.

No runtime deps

Features