BinaryOperator

Trait BinaryOperator 

Source
pub trait BinaryOperator {
    // Required method
    fn precedence(&self) -> u8;
}
Expand description

Trait required for values used as the BinaryOp arm of an InfixToken or PostfixToken.

§Example

enum MyBinaryOp {
    Add,
    Sub,
    Mul,
    Div,
}


impl fixit::BinaryOperator for MyBinaryOp {
    fn precedence(&self) -> u8 {
        match self {
            MyBinaryOp::Add => 1,
            MyBinaryOp::Sub => 1,
            MyBinaryOp::Mul => 2,
            MyBinaryOp::Div => 2,
        }
    }
}

Required Methods§

Source

fn precedence(&self) -> u8

The precedence of the operator, i.e. how tightly it is bound to its two operands. Higher values mean operators that are applied first.

For example, in a typical arithmetic expression, the multiplication operator has a higher precedence than the addition operator.

Actual precedence values do not matter, only their relative values.

Implementors§