pub struct BitSet(pub Vec<u64>);Expand description
A length-prefixed bit set.
The wire representation is a VarInt length prefix followed by that many
64-bit words, encoded in big-endian order. The ith bit is set when:
(data[i / 64] & (1 << (i % 64))) != 0§Examples
use mcproto_types::{TypeCodec, basic::BitSet};
let bits = BitSet(vec![0b0000_0101]);
let mut encoded = Vec::new();
bits.encode(&mut encoded)?;
assert_eq!(
encoded,
[0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05]
);
let mut input = encoded.as_slice();
assert_eq!(BitSet::decode(&mut input)?, bits);
assert!(input.is_empty());
assert!(bits.contains(0));
assert!(!bits.contains(1));
assert!(bits.contains(2));Tuple Fields§
§0: Vec<u64>The packed 64-bit words, in little-endian bit order.
Implementations§
Trait Implementations§
impl Eq for BitSet
impl StructuralPartialEq for BitSet
Auto Trait Implementations§
impl Freeze for BitSet
impl RefUnwindSafe for BitSet
impl Send for BitSet
impl Sync for BitSet
impl Unpin for BitSet
impl UnsafeUnpin for BitSet
impl UnwindSafe for BitSet
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ContextualCodec for Twhere
T: TypeCodec,
impl<T> ContextualCodec for Twhere
T: TypeCodec,
Source§fn encode_with_context(
&self,
writer: &mut impl Write,
_context: &Context,
) -> Result<(), CodecError>
fn encode_with_context( &self, writer: &mut impl Write, _context: &Context, ) -> Result<(), CodecError>
Encodes this value using context supplied by its enclosing structure.
Source§fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
Decodes this value using context supplied by its enclosing structure.