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(): returns- trueonly if the predicate does not evaluate to- true.
 
- 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(): returns- trueif any predicate is- true.
- all(): returns- trueif all predicates are- true.
- none(): returns- trueif there is no given predicate.
- some(): returns- trueif there is some given predicate.
- diff(): returns- trueif any predicate has a different text.
- same(): returns- trueif all the predicates have the same text.
- xany(): returns- trueif there are any- truepredicates, but not all.
- xodd(): returns- trueif there is an odd number of- truepredicates.
- xone(): returns- trueif there is just one- truepredicate, but no more.
 
- 
pointer width: - pointer_width_eq(width): returns- trueif current pointer width == the given width.
- pointer_width_ne(width): returns- trueif current pointer width != the given width.
- pointer_width_ge(width): returns- trueif current pointer width >= the given width.
- pointer_width_gt(width): returns- trueif current pointer width > the given width.
- pointer_width_le(width): returns- trueif current pointer width <= the given width.
- pointer_width_lt(width): returns- trueif current pointer width < the given width.
 
- 
endianness: - little_endian(): returns- trueif current architecture is little-endian.
- big_endian(): returns- trueif current architecture is big-endian.
 
When more than 1 predicate is supported, they are separated by commas.
Macros§
- cifalloc
- Evaluates to either a trueoffalseliteral based on the predicate.
- coalescealloc
- Returns the first non-empty argument.
- enumintalloc
- Generates a unit-only enum with variants associated to a specified range.
- field_of alloc
- 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 dep_hashbrownorstd
- Returns the numbers of both total and unique identifiers in its input.
- ident_unique dep_hashbrownorstd
- Returns the number of unique identifiers in its input.
Attribute Macros§
- compilealloc
- Conditionally compiles the thing it is attached to based on the predicate.
- compile_attr alloc
- Conditionally compiles the given attributes based on the predicate.