Expand description
This defines some traits so we can replace ops with method calls of the respective traits (provided they’re in scope) without worrying about argument types (hopefully)
The traits are:
- AddPanic, SubPanic, MulPanic, DivPanic, RemPanic, ShlPanic, ShrPanic, NegPanic
- AddWrap, SubWrap, Mulwrap, DivWrap, RemWrap, ShlWrap, ShrWrap, NegWrap
- AddSaturate, SubSaturate, MulSaturate
The *Panic
traits all panic on overflow, the *Wrap
traits wrap around and the
*Saturate
traits saturate.
Note: This needs a nightly compiler because it uses the specialization feature.
Traits§
- AbsPanic
- Compute the absolute value of
self
, panicking on overflow - AbsSaturate
- Compute the absolute value of
self
, saturating on overflow - AbsWrap
- Compute the absolute value of
self
, wrapping on overflow - AddAssign
Panic - Add a value to a given value in-place, panicking on overflow
- AddAssign
Wrap - Add a value to a given value in-place, wrapping on overflow
- AddPanic
- Add two values, panicking on overflow
- AddSaturate
- Add two values, saturating on overflow
- AddWrap
- Add two values, wrapping on overflow
- DivAssign
Panic - Divide this value by a given value in-place, panicking on overflow
- DivAssign
Wrap - Divide a value by a given value in-place, wrapping on overflow
- DivPanic
- Divide two values, panicking on overflow
- DivSaturate
- Divide two values, saturating on overflow
- DivWrap
- Divide two values, wrapping on overflow
- MulAssign
Panic - Multiply a value with a given value in-place, panicking on overflow
- MulAssign
Wrap - Multiply a value with a given value in-place, wrapping on overflow
- MulPanic
- Multiply two values, panicking on overflow
- MulSaturate
- Multiply two values, saturating on overflow
- MulWrap
- Multiply two values, wrapping on overflow
- NegPanic
- Negate a value, panic on overflow
- NegSaturate
- Negate a value, saturate on overflow
- NegWrap
- Negate a value, wrap on overflow
- RemAssign
Panic - Get the remainder of dividing this value by a given value in-place, panicking on overflow
- RemAssign
Wrap - Divide a value to a given value, getting the remainder in-place, wrapping on overflow
- RemPanic
- Get the remainder of dividing one value by another, panicking on overflow
- RemSaturate
- Divide two values and get the remainder, saturating on overflow
- RemWrap
- Divide two values and get the remainder, wrapping on overflow
- ShlAssign
Panic - Shift left in place, panic if bits are shifted out of the value
- ShlAssign
Saturate - Shift left in place, set self to 0 if the number of bits shifted are higher than the width of the type
- ShlAssign
Wrap - Shift left in place, set self to 0 if the number of bits shifted are higher than the width of the type
- ShlPanic
- Shift left, panic if bits are shifted out of the value
- ShlSaturate
- Shift left, return 0 if the number of bits shifted are higher than the width of the type
- ShlWrap
- Shift left, return 0 if the number of bits shifted are higher than the width of the type
- ShrAssign
Panic - Shift right in place, panic if the number of bits shifted are higher than the width of the type
- ShrAssign
Saturate - Shift right in place, set self to 0 if the number of bits shifted are higher than the width of the type
- ShrAssign
Wrap - Shift right in place, set self to 0 if the number of bits shifted are higher than the width of the type
- ShrPanic
- Shift right, panic if the number of bits shifted are higher than the width of the type
- ShrSaturate
- Shift right, return 0 if the number of bits shifted are higher than the width of the type
- ShrSaturate
Assign - Shift right in place, set self to 0 if the number of bits shifted are higher than the width of the type
- ShrWrap
- Shift right, return 0 if the number of bits shifted are higher than the width of the type
- SubAssign
Panic - SUbtract a value from a given value in-place, panicking on overflow
- SubAssign
Wrap - Subtract a value from a given value in-place, wrapping on overflow
- SubPanic
- Subtract two values, panicking on overflow
- SubSaturate
- Subtract two values, saturating on overflow
- SubWrap
- Subtract two values, wrapping on overflow