pub enum Bytes {
Len(usize),
Pattern(&'static [u8]),
PatternUntil(&'static [u8], usize),
}
Expand description
Context for &u8 to determine where the slice ends.
Pattern will be included in the result
§Example
use byte::*;
use byte::ctx::*;
let bytes: &[u8] = &[0xde, 0xad, 0xbe, 0xef, 0x00, 0xff];
let sub: &[u8] = bytes.read_with(&mut 0, Bytes::Len(2)).unwrap();
assert_eq!(sub, &[0xde, 0xad]);
static PATTERN: &'static [u8; 2] = &[0x00, 0xff];
let sub: &[u8] = bytes.read_with(&mut 0, Bytes::Pattern(PATTERN)).unwrap();
assert_eq!(sub, &[0xde, 0xad, 0xbe, 0xef, 0x00, 0xff]);
let sub: &[u8] = bytes.read_with(&mut 0, Bytes::PatternUntil(PATTERN, 4)).unwrap();
assert_eq!(sub, &[0xde, 0xad, 0xbe, 0xef]);
Variants§
Len(usize)
Take fix-length bytes
Pattern(&'static [u8])
Take bytes until reaching a byte pattern
PatternUntil(&'static [u8], usize)
Take bytes until either byte pattern or length reached
Trait Implementations§
impl Copy for Bytes
impl Eq for Bytes
impl StructuralPartialEq for Bytes
Auto Trait Implementations§
impl Freeze for Bytes
impl RefUnwindSafe for Bytes
impl Send for Bytes
impl Sync for Bytes
impl Unpin for Bytes
impl UnwindSafe for Bytes
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