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
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.diff(): returnstrueif any predicate has a different text.same(): returnstrueif all the predicates have the same text.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.
When more than 1 predicate is supported, they are separated by commas.
Macros§
- cif
alloc - coalesce
allocReturns the first non-empty argument. - enumint
allocGenerates a unit-only enum with variants associated to a specified range. - ident_
total allocReturns the total number of identifiers in its input. - Returns the numbers of both total and unique identifiers in its input.
- ident_
unique stdReturns the number of unique identifiers in its input.
Attribute Macros§
- compile
allocConditionally compiles the thing it is attached to based on the compilation predicate. - compile_
attr allocConditionally compiles the given attributes based on the compilation predicate.