Struct bytecode::ByteCode

source ·
pub struct ByteCode<'a> { /* private fields */ }

Implementations

Creates a new ByteCode.

Examples
use bytecode::ByteCode;

let bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);

Extracts a current remaining slice.

Equivalent to &bytes[..].

Examples
use bytecode::ByteCode;

let bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);
let slice = bytes.as_slice();

Returns the number of elements.

Note that consumed elements are also counted.

Examples
use bytecode::ByteCode;

let bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);
assert_eq!(bytes.len(), 8);

Resets the pointer to original state.

Examples
use bytecode::ByteCode;

let v = vec![0, 1, 2, 3, 4, 5, 6, 7];
let mut bytes = ByteCode::new(&v);
bytes += 5;
assert_eq!(bytes.as_slice(), [5, 6, 7]);
bytes.reset();
assert_eq!(bytes.as_slice(), v);

Returns true if all elements have been consumed.

Examples
use bytecode::ByteCode;

let mut bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);

bytes += 8;
assert!(bytes.is_end());

bytes -= 6;
assert!(!bytes.is_end());

Returns a reference to subslice corresponding to the given size.

Examples
use bytecode::ByteCode;

let bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);
assert_eq!(bytes.peek(3), [0, 1, 2]);

Returns true if given subslice is a prefix of the slice.

Examples
use bytecode::ByteCode;

let bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);
assert!(bytes.starts_with(&[0, 1, 2]));

Move the pointer to the next. Note that nothing is returned.

Equivalent to bytes += 1.

Examples
use bytecode::ByteCode;

let mut bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);
bytes += 3;

Move the pointer to the prev. Note that nothing is returned.

Equivalent to bytes -= 1.

Examples
use bytecode::ByteCode;

let mut bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);
bytes += 5;
bytes -= 3;

Move the pointer forward by the given number.

Equivalent to bytes += num.

Examples
use bytecode::ByteCode;

let mut bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);
bytes.skip(3);

Returns a vector containing a copy of subslice corresponding to the given size. Moves the pointer forward by the length of subslice.

Examples
use bytecode::ByteCode;

let mut bytes = ByteCode::new(&[0, 1, 2, 3, 4, 5, 6, 7]);
assert_eq!(bytes.take(3), [0, 1, 2]);

Returns the first 2 elements of the slice converted into u16. Moves the pointer forward 2.

Examples
use bytecode::ByteCode;

let mut bytes = ByteCode::new(&[0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
assert_eq!(bytes.take_into_u16(), u16::MAX);

Returns the first 4 elements of the slice converted into u32. Moves the pointer forward 4.

Examples
use bytecode::ByteCode;

let mut bytes = ByteCode::new(&[0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00]);
assert_eq!(bytes.take_into_u32(), u32::MAX);

Returns the string consisting of the given number of bytes from the beginning of the slice. Moves the pointer forward by given number.

Examples
use bytecode::ByteCode;
 
let mut bytes = ByteCode::new(&[0x66, 0x6f, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00]);
assert_eq!(bytes.take_into_string(3), "foo".to_owned());

Trait Implementations

Move the pointer to the next.

Formats the value using the given formatter. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more

Move the pointer to the prev.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.