pub trait BitArith {
type Other: ?Sized;
// Required methods
fn bit_be_cmp(&self, other: &Self) -> Ordering;
fn bit_be_add(&mut self, other: &Self::Other) -> bool;
fn bit_be_sub(&mut self, other: &Self::Other) -> bool;
fn bit_be_mul(&mut self, other: &Self::Other) -> bool;
fn bit_be_div(&mut self, other: &Self::Other) -> bool;
fn bit_be_rem(&mut self, other: &Self::Other) -> bool;
}Expand description
Arithmetic operations implementation for [u8]
Required Associated Types§
Required Methods§
Sourcefn bit_be_cmp(&self, other: &Self) -> Ordering
fn bit_be_cmp(&self, other: &Self) -> Ordering
Comparison for big-endian
§Examples
assert_eq!([0b0011_0011, 0b0011_0011].bit_be_cmp(&[0b1111_1111]), Ordering::Greater);
assert_eq!([0b0000_0000, 0b0011_0011].bit_be_cmp(&[0b1111_1111]), Ordering::Less);
assert_eq!([0b0011_0011, 0b0011_0011].bit_be_cmp(&[0b0000_0000, 0b1111_1111]), Ordering::Greater);
assert_eq!([0b0011_0011, 0b0011_0011].bit_be_cmp(&[0b1111_1111, 0b0000_0000]), Ordering::Less);Sourcefn bit_be_add(&mut self, other: &Self::Other) -> bool
fn bit_be_add(&mut self, other: &Self::Other) -> bool
Bit arithmetic operator += for big-endian
§Example
let (mut a, b) = ([0b1100_1100, 0b1000_0001], [0b1000_0001]);
assert_eq!(a.as_mut().bit_be_add(&b), false);
assert_eq!(a, [0b1100_1101, 0b0000_0010]);Sourcefn bit_be_sub(&mut self, other: &Self::Other) -> bool
fn bit_be_sub(&mut self, other: &Self::Other) -> bool
Bit arithmetic operator -= for big-endian
§Example
let (mut a, b) = ([0b1100_1100, 0b1000_0001], [0b1000_0001]);
assert_eq!(a.as_mut().bit_be_sub(&b), false);
assert_eq!(a, [0b1100_1100, 0b0000_0000]);Sourcefn bit_be_mul(&mut self, other: &Self::Other) -> bool
fn bit_be_mul(&mut self, other: &Self::Other) -> bool
Bit arithmetic operator *= for big-endian
§Example
let (mut a, b) = ([0b0011_0000, 0b1000_0001], [0b0000_0010]);
assert_eq!(a.as_mut().bit_be_mul(&b), false);
assert_eq!(a, [0b0110_0001, 0b0000_0010]);Sourcefn bit_be_div(&mut self, other: &Self::Other) -> bool
fn bit_be_div(&mut self, other: &Self::Other) -> bool
Bit arithmetic operator /= for big-endian
§Example
let (a, b) = ([0b1100_0011, 0b0000_0001], [0b1000_0001]);
let mut x = a.clone();
x.as_mut().bit_be_div(&b);
assert_eq!(x, (u16::from_be_bytes(a) / u16::from_be_bytes([0, b[0]])).to_be_bytes());Sourcefn bit_be_rem(&mut self, other: &Self::Other) -> bool
fn bit_be_rem(&mut self, other: &Self::Other) -> bool
Bit arithmetic operator %= for big-endian
§Example
let (a, b) = ([0b1100_0011, 0b0000_0001], [0b0000_0001, 0b1000_0001]);
let mut x = a.clone();
x.as_mut().bit_be_rem(&b);
// assert_eq!(x, (u16::from_be_bytes(a) % u16::from_be_bytes(b)).to_be_bytes());Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.