#[non_exhaustive]pub enum BitOp {
And,
Or,
Xor,
Not,
}Expand description
Operator for the BITOP family.
use kevy_store::BitOp;
// NOT takes exactly one source; the callers enforce that, and this
// is what it computes.
assert_eq!(BitOp::Not.combine(&[vec![0b1010_1010]], 1), vec![0b0101_0101]);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
And
Bitwise AND across source keys.
use kevy_store::BitOp;
assert_eq!(BitOp::And.combine(&[vec![0b1100], vec![0b1010]], 1), vec![0b1000]);Or
Bitwise OR across source keys.
use kevy_store::BitOp;
assert_eq!(BitOp::Or.combine(&[vec![0b1100], vec![0b1010]], 1), vec![0b1110]);Xor
Bitwise XOR across source keys.
use kevy_store::BitOp;
assert_eq!(BitOp::Xor.combine(&[vec![0b1100], vec![0b1010]], 1), vec![0b0110]);Not
Bitwise NOT — exactly one source key.
use kevy_store::BitOp;
assert_eq!(BitOp::Not.combine(&[vec![0x0f]], 1), vec![0xf0]);Implementations§
Source§impl BitOp
impl BitOp
Sourcepub fn combine(self, srcs_bytes: &[Vec<u8>], max_len: usize) -> Vec<u8> ⓘ
pub fn combine(self, srcs_bytes: &[Vec<u8>], max_len: usize) -> Vec<u8> ⓘ
Combine the source strings under this operator into the max_len-byte
destination value (shorter sources zero-padded).
Two rules are easy to get wrong and both are here. A source shorter
than the result reads as zero past its end — so an AND with a short
source clears the tail, and an OR leaves it alone. And NOT does not
stop at its source: Redis inverts the implicit zeros too, so every
byte past the source is 0xff.
use kevy_store::BitOp;
let long = b"\xff\xff".to_vec();
let short = b"\x0f".to_vec();
// AND: the second byte meets an implicit zero.
assert_eq!(BitOp::And.combine(&[long.clone(), short.clone()], 2), vec![0x0f, 0x00]);
// OR: the implicit zero changes nothing.
assert_eq!(BitOp::Or.combine(&[long.clone(), short], 2), vec![0xff, 0xff]);
// NOT over a two-byte result from a one-byte source: the tail is 0xff.
assert_eq!(BitOp::Not.combine(&[vec![0x00]], 2), vec![0xff, 0xff]);Trait Implementations§
impl Copy for BitOp
impl Eq for BitOp
impl StructuralPartialEq for BitOp
Auto Trait Implementations§
impl Freeze for BitOp
impl RefUnwindSafe for BitOp
impl Send for BitOp
impl Sync for BitOp
impl Unpin for BitOp
impl UnsafeUnpin for BitOp
impl UnwindSafe for BitOp
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
Mutably borrows from an owned value. Read more