Struct tarrasque::UnwrapStream
source · pub struct UnwrapStream<'a>(pub Stream<'a>);
Expand description
A Stream
wrapper that unwraps extracted values.
Tuple Fields
0: Stream<'a>
Implementations
sourceimpl<'a> UnwrapStream<'a>
impl<'a> UnwrapStream<'a>
Methods from Deref<Target = Stream<'a>>
sourcepub fn extract<T, P>(&mut self, parameter: P) -> ExtractResult<'a, T>where
T: Extract<'a, P>,
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)));
sourcepub fn peek<T, P>(&mut self, parameter: P) -> ExtractResult<'a, T>where
T: Extract<'a, P>,
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)));
sourcepub fn skip(&mut self, n: usize)
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)));
sourcepub fn skip_while<F: Fn(u8) -> bool>(&mut self, f: F)
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
sourceimpl<'a> Clone for UnwrapStream<'a>
impl<'a> Clone for UnwrapStream<'a>
sourcefn clone(&self) -> UnwrapStream<'a>
fn clone(&self) -> UnwrapStream<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<'a> Debug for UnwrapStream<'a>
impl<'a> Debug for UnwrapStream<'a>
sourceimpl<'a> Deref for UnwrapStream<'a>
impl<'a> Deref for UnwrapStream<'a>
sourceimpl<'a> DerefMut for UnwrapStream<'a>
impl<'a> DerefMut for UnwrapStream<'a>
sourceimpl<'a> PartialEq<UnwrapStream<'a>> for UnwrapStream<'a>
impl<'a> PartialEq<UnwrapStream<'a>> for UnwrapStream<'a>
sourcefn eq(&self, other: &UnwrapStream<'a>) -> bool
fn eq(&self, other: &UnwrapStream<'a>) -> bool
impl<'a> Copy for UnwrapStream<'a>
impl<'a> Eq for UnwrapStream<'a>
impl<'a> StructuralEq for UnwrapStream<'a>
impl<'a> StructuralPartialEq for UnwrapStream<'a>
Auto Trait Implementations
impl<'a> RefUnwindSafe for UnwrapStream<'a>
impl<'a> Send for UnwrapStream<'a>
impl<'a> Sync for UnwrapStream<'a>
impl<'a> Unpin for UnwrapStream<'a>
impl<'a> UnwindSafe for UnwrapStream<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more