Enum byte::ctx::Bytes [] [src]

pub enum Bytes {
    Len(usize),
    Pattern(&'static [u8]),
    PatternUntil(&'static [u8], usize),
}

Context for &[u8] to determine where the slice ends.

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

Take fix-length bytes

Take bytes until reaching a byte pattern

Take bytes until either byte pattern or length reached

Trait Implementations

impl Debug for Bytes
[src]

Formats the value using the given formatter.

impl PartialEq for Bytes
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for Bytes
[src]

impl Copy for Bytes
[src]

impl Clone for Bytes
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more