Function logicHandler

Source
pub fn logicHandler<T: StartMarker + Clone>(
    c: Configuration<T>,
    v: Variables<'_, T>,
    data: Option<TokenStream>,
    t: TokenStream,
) -> Result<(Variables<'_, T>, TokenStream), (Variables<'_, T>, TokenStream)>
Expand description

Handle logic expressions with a nestable sublanguage

Basic usage: $(logic <expression>).

Returns true or false based on evaluating standard boolean logic expressions. Subexpressions can be created using parenthesis and nested arbitrarily.

OperatorLogical Operation
A & BAND (conjunction)
A | BOR (disjunction)
A ^ BXOR (exclusive OR)
A = BEQUAL (equivalence)
! ANOT (negation)
trueTRUE literal
falseFALSE literal

Numeric comparisons are also supported between numeric values:

OperatorNumeric operation
X > YGreater-than
X >= YGreater-than or equal to
X = YEqual to
X <= YLess-than or equal to
X < YLess-than
X != YNot equal to

Finally, subexpressions of the form (eq_str "a" "b") can be used to do string equality comparisons.

§Examples

// Logic expression returns true or false
let x1 = $(logic false | true); // x1 = true
 
// Nesting is supported
let xf = $(logic (false | (! false)) | ((true = true) & (! false))); // xf = true
 
// Numeric comparison
$(logic $N < $M)
 
// Use within an $(if) handler and containing a $(arithmetic) expression.
$(if { $(logic $(arithmetic u64u (($N * $WORDSIZE) % ((size_of u8) * 8))) = 0) } { 0 } { 1 })

See do_with_in_test.rs for more examples.