Struct tarrasque::Stream[][src]

pub struct Stream<'a>(pub &'a [u8]);

A stream of bytes from which values can be extracted.

Methods

impl<'a> Stream<'a>
[src]

Extracts bytes from this stream as a T.

Example

let mut stream = Stream(&[1, 2]);
assert_eq!(stream.extract::<u8, _>(()), Ok(0x01));
assert_eq!(stream.extract::<u8, _>(()), Ok(0x02));
assert_eq!(stream.extract::<u8, _>(()), Err(ExtractError::Insufficient(1)));

Returns bytes from this stream as a T without extracting the bytes.

Example

let mut stream = Stream(&[1, 2, 3, 4]);
assert_eq!(stream.peek::<u16, _>(()), Ok(0x0102));
assert_eq!(stream.extract::<u16, _>(()), Ok(0x0102));
assert_eq!(stream.peek::<u16, _>(()), Ok(0x0304));
assert_eq!(stream.extract::<u16, _>(()), Ok(0x0304));
assert_eq!(stream.peek::<u16, _>(()), Err(ExtractError::Insufficient(2)));
assert_eq!(stream.extract::<u16, _>(()), Err(ExtractError::Insufficient(2)));

Skips the supplied number of bytes in this stream.

Example

let mut stream = Stream(&[1, 2, 3, 4]);
stream.skip(2);
assert_eq!(stream.extract::<u16, _>(()), Ok(0x0304));
assert_eq!(stream.extract::<u16, _>(()), Err(ExtractError::Insufficient(2)));

Skips bytes in this stream while the supplied condition is true for those bytes.

Example

let mut stream = Stream(&[1, 2, 3, 4]);
stream.skip_while(|b| b < 3);
assert_eq!(stream.extract::<u16, _>(()), Ok(0x0304));
assert_eq!(stream.extract::<u16, _>(()), Err(ExtractError::Insufficient(2)));

Trait Implementations

impl<'a> Copy for Stream<'a>
[src]

impl<'a> Clone for Stream<'a>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> Debug for Stream<'a>
[src]

Formats the value using the given formatter. Read more

impl<'a> PartialEq for Stream<'a>
[src]

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

This method tests for !=.

impl<'a> Eq for Stream<'a>
[src]

Auto Trait Implementations

impl<'a> Send for Stream<'a>

impl<'a> Sync for Stream<'a>