13 releases (breaking)
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 |
#2021 in Procedural macros
312 downloads per month
Used in 12 crates
(via devela)
30KB
419 lines
devela_macros
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 thetrue
literal. - A bare predicate returns
false
if it's thefalse
literal or it's empty. not()
: returnstrue
only if the predicate does not evaluate totrue
.
- A bare predicate returns
-
binary:
-
equal()
: returnstrue
if both predicates are evaluated as equal. -
xor()
: returnstrue
if only one predicate istrue
, but not both. -
eq()
: returnstrue
if both predicates are number literals and Left == Right. -
ne()
: returnstrue
if both predicates are number literals and Left != Right. -
ge()
: returnstrue
if both predicates are number literals and Left >= Right. -
gt()
: returnstrue
if both predicates are number literals and Left > Right. -
le()
: returnstrue
if both predicates are number literals and Left <= Right. -
lt()
: returnstrue
if both predicates are number literals and Left < Right.
-
-
non-binary:
any()
: returnstrue
if any predicate istrue
.all()
: returnstrue
if all predicates aretrue
.none()
: returnstrue
if there is no given predicate.some()
: returnstrue
if there is some given predicate.diff()
: returnstrue
if any predicate has a different text.same()
: returnstrue
if all the predicates have the same text.xany()
: returnstrue
if there are anytrue
predicates, but not all.xodd()
: returnstrue
if there is an odd number oftrue
predicates.xone()
: returnstrue
if there is just onetrue
predicate, but no more.
-
pointer width:
pointer_width_eq(width)
: returnstrue
if current pointer width == the given width.pointer_width_ne(width)
: returnstrue
if current pointer width != the given width.pointer_width_ge(width)
: returnstrue
if current pointer width >= the given width.pointer_width_gt(width)
: returnstrue
if current pointer width > the given width.pointer_width_le(width)
: returnstrue
if current pointer width <= the given width.pointer_width_lt(width)
: returnstrue
if current pointer width < the given width.
-
endianness:
little_endian()
: returnstrue
if current architecture is little-endian.big_endian()
: returnstrue
if current architecture is big-endian.
When more than 1 predicate is supported, they are separated by commas.