Struct bytecodec::bytes::BytesDecoder
[−]
[src]
pub struct BytesDecoder<B> { /* fields omitted */ }BytesDecoder copies bytes from an input sequence to a slice.
This is a oneshot decoder (i.e., it decodes only one item).
Examples
use bytecodec::{Decode, DecodeBuf}; use bytecodec::bytes::BytesDecoder; let mut decoder = BytesDecoder::new([0; 3]); assert_eq!(decoder.requiring_bytes_hint(), Some(3)); let mut input = DecodeBuf::new(b"foobar"); let item = decoder.decode(&mut input).unwrap(); assert_eq!(item.as_ref(), Some(b"foo")); assert_eq!(decoder.requiring_bytes_hint(), Some(0)); // no more items are decoded
Methods
impl<B> BytesDecoder<B>[src]
pub fn new(bytes: B) -> Self[src]
Makes a new BytesDecoder instance for filling the given byte slice.
Trait Implementations
impl<B: Debug> Debug for BytesDecoder<B>[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result[src]
Formats the value using the given formatter. Read more
impl<B: AsRef<[u8]> + AsMut<[u8]>> Decode for BytesDecoder<B>[src]
type Item = B
The type of items to be decoded.
fn decode(&mut self, buf: &mut DecodeBuf) -> Result<Option<Self::Item>>[src]
Consumes the given buffer (a part of a byte sequence), and decodes an item from it. Read more
fn has_terminated(&self) -> bool[src]
Returns true if the decoder cannot decode items anymore, otherwise false. Read more
fn is_idle(&self) -> bool[src]
Returns true if the decoder does not have an item that being decoded, otherwise false.
fn requiring_bytes_hint(&self) -> Option<u64>[src]
Returns the lower bound of the number of bytes needed to decode the next item. Read more
Auto Trait Implementations
impl<B> Send for BytesDecoder<B> where
B: Send,
B: Send,
impl<B> Sync for BytesDecoder<B> where
B: Sync,
B: Sync,