Enum BinaryOp
pub enum BinaryOp {
Eq,
Ne,
Ge,
Gt,
Le,
Lt,
Add,
Sub,
}Expand description
A binary operator: comparison or arithmetic.
Used by ExprBinaryOp to specify the operation
applied between two expressions.
§Examples
use toasty_core::stmt::BinaryOp;
let op = BinaryOp::Eq;
assert!(op.is_eq());
assert_eq!(op.to_string(), "=");
// Negation
assert_eq!(op.negate(), Some(BinaryOp::Ne));
// Commutation (swapping operands)
assert_eq!(BinaryOp::Lt.commute(), Some(BinaryOp::Gt));
assert_eq!(BinaryOp::Add.commute(), Some(BinaryOp::Add));
assert_eq!(BinaryOp::Sub.commute(), None);Variants§
Eq
Equality (=).
Ne
Inequality (!=).
Ge
Greater than or equal (>=).
Gt
Greater than (>).
Le
Less than or equal (<=).
Lt
Less than (<).
Add
Arithmetic addition (+).
Sub
Arithmetic subtraction (-).
Implementations§
§impl BinaryOp
impl BinaryOp
pub fn is_arithmetic(self) -> bool
pub fn is_arithmetic(self) -> bool
Returns true if this is an arithmetic operator (+, -).
pub fn negate(self) -> Option<BinaryOp>
pub fn negate(self) -> Option<BinaryOp>
Returns the logical negation of this operator, if one exists.
Only comparison operators have a logical negation; arithmetic
operators return None.
=→!=!=→=<→>=>=→<>→<=<=→>
pub fn commute(self) -> Option<BinaryOp>
pub fn commute(self) -> Option<BinaryOp>
Returns the operator that gives an equivalent result when the operands
are swapped, or None if the operator is not commutative.
For example, 5 < x becomes x > 5, so Lt.commute() returns
Some(Gt). Symmetric operators (Eq, Ne, Add) return themselves.
Sub is not commutative (a - b ≠ b - a) and returns None.
Trait Implementations§
impl Copy for BinaryOp
impl Eq for BinaryOp
impl StructuralPartialEq for BinaryOp
Auto Trait Implementations§
impl Freeze for BinaryOp
impl RefUnwindSafe for BinaryOp
impl Send for BinaryOp
impl Sync for BinaryOp
impl Unpin for BinaryOp
impl UnsafeUnpin for BinaryOp
impl UnwindSafe for BinaryOp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.