Expand description
A development substrate of coherence.
Procedural macros for devela.
§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.
§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
trueonly if it is thetrueliteral. - A bare predicate returns
falseif it’s thefalseliteral or it’s empty. not(): returnstrueonly if the predicate does not evaluate totrue.
- A bare predicate returns
-
binary:
-
equal(): returnstrueif both predicates are evaluated as equal. -
xor(): returnstrueif only one predicate istrue, but not both. -
eq(): returnstrueif both predicates are number literals and Left == Right. -
ne(): returnstrueif both predicates are number literals and Left != Right. -
ge(): returnstrueif both predicates are number literals and Left >= Right. -
gt(): returnstrueif both predicates are number literals and Left > Right. -
le(): returnstrueif both predicates are number literals and Left <= Right. -
lt(): returnstrueif both predicates are number literals and Left < Right.
-
-
non-binary:
any(): returnstrueif any predicate istrue.all(): returnstrueif all predicates aretrue.none(): returnstrueif there is no given predicate.some(): returnstrueif there is some given predicate.same(): returnstrueif all the predicates have the same text.diff(): returnstrueif any predicate differs from the first in text.nota(): returnstrueif the first predicate’s text matches none of the additional predicates.xany(): returnstrueif there are anytruepredicates, but not all.xodd(): returnstrueif there is an odd number oftruepredicates.xone(): returnstrueif there is just onetruepredicate, but no more.
-
pointer width:
pointer_width_eq(width): returnstrueif current pointer width == the given width.pointer_width_ne(width): returnstrueif current pointer width != the given width.pointer_width_ge(width): returnstrueif current pointer width >= the given width.pointer_width_gt(width): returnstrueif current pointer width > the given width.pointer_width_le(width): returnstrueif current pointer width <= the given width.pointer_width_lt(width): returnstrueif current pointer width < the given width.
-
endianness:
little_endian(): returnstrueif current architecture is little-endian.big_endian(): returnstrueif current architecture is big-endian.
-
environment variables:
env(NAME): returnstrueif the env var exists.env_eq(NAME, VALUE): returnstrueif the env var exists and its value == VALUE.env_ne(NAME, VALUE): returnstrueif the env var exists and its value != VALUE.env_empty(NAME): returnstrueif the env var exists and its value is empty.env_nonempty(NAME): returnstrueif the env var exists and its value is non-empty.
§Notes
- When more than one predicate is supported, they are separated by commas.
- Env predicates compare textual values, not numeric or boolean coercions.
Empty-argument semantics:
all()==trueany()==falsesame()==truediff()==falsenone()==truesome()==falsenota()== panic (no reference predicate)
Macros§
- cif
- Evaluates to either a
trueoffalseliteral based on the predicate. - coalesce
- Returns the first non-empty argument.
- enumint
- Generates a unit-only enum with variants associated to a specified range.
- field_
of - Generates an expression for accessing a field of a tuple or struct.
- ident_
total - Returns the total number of identifiers in its input.
- ident_
total_ unique - Returns the numbers of both total and unique identifiers in its input.
- ident_
unique - Returns the number of unique identifiers in its input.
- repeat
- Repeats an expression the given number of times, as duplicated code with no loops.
Attribute Macros§
- compile
- Conditionally compiles the thing it is attached to based on the predicate.
- compile_
attr - Conditionally compiles the given attributes based on the predicate.