pub enum BinOp {
Show 26 variants
Add,
AddUnchecked,
AddWithOverflow,
Sub,
SubUnchecked,
SubWithOverflow,
Mul,
MulUnchecked,
MulWithOverflow,
Div,
Rem,
BitXor,
BitAnd,
BitOr,
Shl,
ShlUnchecked,
Shr,
ShrUnchecked,
Eq,
Lt,
Le,
Ne,
Ge,
Gt,
Cmp,
Offset,
}
Variants§
Add
The +
operator (addition)
AddUnchecked
Like Add
, but with UB on overflow. (Integers only.)
AddWithOverflow
Like Add
, but returns (T, bool)
of both the wrapped result
and a bool indicating whether it overflowed.
Sub
The -
operator (subtraction)
SubUnchecked
Like Sub
, but with UB on overflow. (Integers only.)
SubWithOverflow
Like Sub
, but returns (T, bool)
of both the wrapped result
and a bool indicating whether it overflowed.
Mul
The *
operator (multiplication)
MulUnchecked
Like Mul
, but with UB on overflow. (Integers only.)
MulWithOverflow
Like Mul
, but returns (T, bool)
of both the wrapped result
and a bool indicating whether it overflowed.
Div
The /
operator (division)
For integer types, division by zero is UB, as is MIN / -1
for signed.
The compiler should have inserted checks prior to this.
Floating-point division by zero is safe, and does not need guards.
Rem
The %
operator (modulus)
For integer types, using zero as the modulus (second operand) is UB,
as is MIN % -1
for signed.
The compiler should have inserted checks prior to this.
Floating-point remainder by zero is safe, and does not need guards.
BitXor
The ^
operator (bitwise xor)
BitAnd
The &
operator (bitwise and)
BitOr
The |
operator (bitwise or)
Shl
The <<
operator (shift left)
The offset is given by RHS.rem_euclid(LHS::BITS)
.
In other words, it is (uniquely) determined as follows:
- it is “equal modulo LHS::BITS” to the RHS
- it is in the range
0..LHS::BITS
ShlUnchecked
Like Shl
, but is UB if the RHS >= LHS::BITS or RHS < 0
Shr
The >>
operator (shift right)
The offset is given by RHS.rem_euclid(LHS::BITS)
.
In other words, it is (uniquely) determined as follows:
- it is “equal modulo LHS::BITS” to the RHS
- it is in the range
0..LHS::BITS
This is an arithmetic shift if the LHS is signed and a logical shift if the LHS is unsigned.
ShrUnchecked
Like Shl
, but is UB if the RHS >= LHS::BITS or RHS < 0
Eq
The ==
operator (equality)
Lt
The <
operator (less than)
Le
The <=
operator (less than or equal to)
Ne
The !=
operator (not equal to)
Ge
The >=
operator (greater than or equal to)
Gt
The >
operator (greater than)
Cmp
The <=>
operator (three-way comparison, like Ord::cmp
)
This is supported only on the integer types and char
, always returning
[rustc_hir::LangItem::OrderingEnum
] (aka std::cmp::Ordering
).
Rvalue::BinaryOp
(BinOp::Cmp, A, B)
returns
Ordering::Less
(-1_i8
, as a Scalar) ifA < B
Ordering::Equal
(0_i8
, as a Scalar) ifA == B
Ordering::Greater
(+1_i8
, as a Scalar) ifA > B
Offset
The ptr.offset
operator