Struct Length

Source
pub struct Length<C> { /* private fields */ }
Expand description

Combinator for consuming the specified number of bytes exactly.

This is created by calling {DecodeExt, EncodeExt}::length method.

Implementations§

Source§

impl<C> Length<C>

Source

pub fn expected_bytes(&self) -> u64

Returns the number of bytes expected to be consumed for decoding an item.

Source

pub fn set_expected_bytes(&mut self, bytes: u64) -> Result<()>

Sets the number of bytes expected to be consumed for decoding an item.

§Errors

If it is in the middle of decoding an item, it willl return an ErrorKind::IncompleteDecoding error.

Source

pub fn remaining_bytes(&self) -> u64

Returns the number of remaining bytes required to decode the next item.

Source

pub fn inner_ref(&self) -> &C

Returns a reference to the inner encoder or decoder.

Source

pub fn inner_mut(&mut self) -> &mut C

Returns a mutable reference to the inner encoder or decoder.

Source

pub fn into_inner(self) -> C

Takes ownership of this instance and returns the inner encoder or decoder.

Trait Implementations§

Source§

impl<C: Debug> Debug for Length<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<D: Decode> Decode for Length<D>

Source§

type Item = <D as Decode>::Item

The type of items to be decoded.
Source§

fn decode(&mut self, buf: &[u8], eos: Eos) -> Result<usize>

Consumes the given buffer (a part of a byte sequence), and proceeds the decoding process. Read more
Source§

fn finish_decoding(&mut self) -> Result<Self::Item>

Finishes the current decoding process and returns the decoded item. Read more
Source§

fn requiring_bytes(&self) -> ByteCount

Returns the lower bound of the number of bytes needed to decode the next item. Read more
Source§

fn is_idle(&self) -> bool

Returns true if there are no items to be decoded by the decoder at the next invocation of decode method, otherwise false. Read more
Source§

impl<C: Default> Default for Length<C>

Source§

fn default() -> Length<C>

Returns the “default value” for a type. Read more
Source§

impl<E: Encode> Encode for Length<E>

Source§

type Item = <E as Encode>::Item

The type of items to be encoded.
Source§

fn encode(&mut self, buf: &mut [u8], eos: Eos) -> Result<usize>

Encodes the items in the encoder and writes the encoded bytes to the given buffer. Read more
Source§

fn start_encoding(&mut self, item: Self::Item) -> Result<()>

Tries to start encoding the given item. Read more
Source§

fn requiring_bytes(&self) -> ByteCount

Returns the number of bytes required to encode all the items in the encoder. Read more
Source§

fn is_idle(&self) -> bool

Returns true if there are no items to be encoded in the encoder, otherwise false. Read more
Source§

impl<E: Encode> SizedEncode for Length<E>

Source§

fn exact_requiring_bytes(&self) -> u64

Returns the exact number of bytes required to encode all the items remaining in the encoder.

Auto Trait Implementations§

§

impl<C> Freeze for Length<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for Length<C>
where C: RefUnwindSafe,

§

impl<C> Send for Length<C>
where C: Send,

§

impl<C> Sync for Length<C>
where C: Sync,

§

impl<C> Unpin for Length<C>
where C: Unpin,

§

impl<C> UnwindSafe for Length<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DecodeExt for T
where T: Decode,

Source§

fn map<T, F>(self, f: F) -> Map<Self, T, F>
where F: Fn(Self::Item) -> T,

Creates a decoder that converts decoded values by calling the given function. Read more
Source§

fn try_map<T, E, F>(self, f: F) -> TryMap<Self, T, E, F>
where F: Fn(Self::Item) -> Result<T, E>, Error: From<E>,

Creates a decoder that tries to convert decoded values by calling the given function. Read more
Source§

fn map_err<E, F>(self, f: F) -> MapErr<Self, E, F>
where F: Fn(Error) -> E, Error: From<E>,

Creates a decoder for modifying decoding errors produced by self. Read more
Source§

fn and_then<D, F>(self, f: F) -> AndThen<Self, D, F>
where F: Fn(Self::Item) -> D, D: Decode,

Creates a decoder that enables conditional decoding. Read more
Source§

fn collect<T>(self) -> Collect<Self, T>
where T: Extend<Self::Item> + Default,

Creates a decoder for collecting decoded items. Read more
Source§

fn collectn<T>(self, n: usize) -> CollectN<Self, T>
where T: Extend<Self::Item> + Default,

Creates a decoder that decodes n items by using self and collecting the result. Read more
Source§

fn length(self, expected_bytes: u64) -> Length<Self>

Creates a decoder that consumes the specified number of bytes exactly. Read more
Source§

fn omit(self, do_omit: bool) -> Omittable<Self>

Creates a decoder that will omit decoding items if do_omit = true is specified. Read more
Source§

fn max_bytes(self, bytes: u64) -> MaxBytes<Self>

Creates a decoder that will fail if the number of consumed bytes exceeds bytes. Read more
Source§

fn chain<T: Decode>(self, other: T) -> TupleDecoder<(Self, T)>

Takes two decoders and creates a new decoder that decodes both items in sequence. Read more
Source§

fn slice(self) -> Slice<Self>

Creates a decoder that makes it possible to slice the input byte sequence in arbitrary units. Read more
Source§

fn peekable(self) -> Peekable<Self>

Creates a decoder that enables to peek decoded items before calling finish_decoding method. Read more
Source§

fn maybe_eos(self) -> MaybeEos<Self>

Creates a decoder that ignores EOS if there is no item being decoded. Read more
Source§

fn decode_from_bytes(&mut self, buf: &[u8]) -> Result<Self::Item>

Decodes an item by consuming the whole part of the given bytes. Read more
Source§

impl<T> EncodeExt for T
where T: Encode,

Source§

fn with_item(item: Self::Item) -> Result<Self>
where Self: Default,

Creates a new encoder instance that has the given initial item. Read more
Source§

fn map_err<E, F>(self, f: F) -> MapErr<Self, E, F>
where F: Fn(Error) -> E, Error: From<E>,

Creates an encoder for modifying encoding errors produced by self. Read more
Source§

fn map_from<T, F>(self, f: F) -> MapFrom<Self, T, F>
where F: Fn(T) -> Self::Item,

Creates an encoder that converts items into ones that suited to the self encoder by calling the given function. Read more
Source§

fn try_map_from<T, E, F>(self, f: F) -> TryMapFrom<Self, T, E, F>
where F: Fn(T) -> Result<Self::Item, E>, Error: From<E>,

Creates an encoder that tries to convert items into ones that suited to the self encoder by calling the given function. Read more
Source§

fn optional(self) -> Optional<Self>

Creates an encoder that represents an optional encoder. Read more
Source§

fn max_bytes(self, n: u64) -> MaxBytes<Self>

Creates an encoder that will fail if the number of encoded bytes of an item exceeds n. Read more
Source§

fn length(self, n: u64) -> Length<Self>

Creates an encoder that required to encode each item exactly at the specified number of bytes. Read more
Source§

fn chain<T: Encode>(self, other: T) -> TupleEncoder<(Self, T)>

Takes two encoders and creates a new encoder that encodes both items in sequence. Read more
Source§

fn repeat<I>(self) -> Repeat<Self, I>
where I: Iterator<Item = Self::Item>,

Creates an encoder that repeats encoding of Self::Item. Read more
Source§

fn pre_encode(self) -> PreEncode<Self>

Creates an encoder that pre-encodes items when start_encoding method is called. Read more
Source§

fn slice(self) -> Slice<Self>

Creates an encoder that makes it possible to slice the encoded byte sequence in arbitrary units. Read more
Source§

fn last(self, item: Self::Item) -> Last<Self>

Creates an encoder that cannot accept any more items except the given one.
Source§

fn encode_into_bytes(&mut self, item: Self::Item) -> Result<Vec<u8>>

Encodes the given item and returns the resulting bytes. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IoDecodeExt for T
where T: Decode,

Source§

fn decode_from_read_buf<B>(&mut self, buf: &mut ReadBuf<B>) -> Result<()>
where B: AsRef<[u8]>,

Consumes bytes from the given read buffer and proceeds the decoding process.
Source§

fn decode_exact<R: Read>(&mut self, reader: R) -> Result<Self::Item>

Decodes an item from the given reader. Read more
Source§

impl<T> IoEncodeExt for T
where T: Encode,

Source§

fn encode_to_write_buf<B>(&mut self, buf: &mut WriteBuf<B>) -> Result<()>
where B: AsMut<[u8]>,

Encodes the items remaining in the encoder and writes the encoded bytes to the given write buffer.
Source§

fn encode_to_write_buf_async<B>( &mut self, buf: &mut WriteBuf<B>, cx: &mut Context<'_>, ) -> Result<()>
where B: AsMut<[u8]>,

Encodes the items remaining in the encoder and writes the encoded bytes to the given write buffer. If the write buffer is full and the writing cannot be performed, the given WriteBuf will memorize cx’s Waker. This Waker’s wake will later be called when the WriteBuf regains its free space.
Source§

fn encode_all<W: Write>(&mut self, writer: W) -> Result<()>

Encodes all of the items remaining in the encoder and writes the encoded bytes to the given writer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.