Struct tarrasque::UnwrapStream [−][src]
pub struct UnwrapStream<'a>(pub Stream<'a>);
A Stream
wrapper that unwraps extracted values.
Methods
impl<'a> UnwrapStream<'a>
[src]
impl<'a> UnwrapStream<'a>
pub fn extract<T, P>(&mut self, parameter: P) -> T where
T: Extract<'a, P>,
[src]
pub fn extract<T, P>(&mut self, parameter: P) -> T where
T: Extract<'a, P>,
Extracts bytes from this stream as a T
and unwraps the result.
Example
let mut stream = UnwrapStream(Stream(&[1, 2])); assert_eq!(stream.extract::<u8, _>(()), 0x01); assert_eq!(stream.extract::<u8, _>(()), 0x02);
Methods from Deref<Target = Stream<'a>>
pub fn extract<T, P>(&mut self, parameter: P) -> ExtractResult<'a, T> where
T: Extract<'a, P>,
[src]
pub fn extract<T, P>(&mut self, parameter: P) -> ExtractResult<'a, T> where
T: Extract<'a, P>,
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)));
pub fn peek<T, P>(&mut self, parameter: P) -> ExtractResult<'a, T> where
T: Extract<'a, P>,
[src]
pub fn peek<T, P>(&mut self, parameter: P) -> ExtractResult<'a, T> where
T: Extract<'a, P>,
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)));
pub fn skip(&mut self, n: usize)
[src]
pub fn skip(&mut self, n: usize)
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)));
pub fn skip_while<F: Fn(u8) -> bool>(&mut self, f: F)
[src]
pub fn skip_while<F: Fn(u8) -> bool>(&mut self, f: F)
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 UnwrapStream<'a>
[src]
impl<'a> Copy for UnwrapStream<'a>
impl<'a> Clone for UnwrapStream<'a>
[src]
impl<'a> Clone for UnwrapStream<'a>
fn clone(&self) -> UnwrapStream<'a>
[src]
fn clone(&self) -> UnwrapStream<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0
[src]Performs copy-assignment from source
. Read more
impl<'a> Debug for UnwrapStream<'a>
[src]
impl<'a> Debug for UnwrapStream<'a>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a> PartialEq for UnwrapStream<'a>
[src]
impl<'a> PartialEq for UnwrapStream<'a>
fn eq(&self, other: &UnwrapStream<'a>) -> bool
[src]
fn eq(&self, other: &UnwrapStream<'a>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &UnwrapStream<'a>) -> bool
[src]
fn ne(&self, other: &UnwrapStream<'a>) -> bool
This method tests for !=
.
impl<'a> Eq for UnwrapStream<'a>
[src]
impl<'a> Eq for UnwrapStream<'a>
impl<'a> Deref for UnwrapStream<'a>
[src]
impl<'a> Deref for UnwrapStream<'a>
type Target = Stream<'a>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
fn deref(&self) -> &Self::Target
Dereferences the value.
impl<'a> DerefMut for UnwrapStream<'a>
[src]
impl<'a> DerefMut for UnwrapStream<'a>
Auto Trait Implementations
impl<'a> Send for UnwrapStream<'a>
impl<'a> Send for UnwrapStream<'a>
impl<'a> Sync for UnwrapStream<'a>
impl<'a> Sync for UnwrapStream<'a>