pub struct BytesCursor { /* private fields */ }Expand description
BytesCursor is a Bytes wrapper implementing Input.
It supports zero-copy decoding of Bytes fields, and provides a
read_bytes method which can be used to implement zero-copy decoding of
other types.
Implementations§
Source§impl BytesCursor
impl BytesCursor
Sourcepub fn infallible_remaining_len(&self) -> usize
pub fn infallible_remaining_len(&self) -> usize
Returns the number of bytes left to read.
Note that this is “infallible” in contrast to Input::remaining_len, which can return
Err or Ok(None).
Sourcepub fn remaining(&mut self) -> &Bytes
pub fn remaining(&mut self) -> &Bytes
Returns a reference to a Bytes object containing the remaining bytes.
The length of the Bytes should match self.infallible_remaining_len().
Sourcepub fn read_bytes(&mut self, len: usize) -> Result<Bytes, Error>
pub fn read_bytes(&mut self, len: usize) -> Result<Bytes, Error>
Read len bytes.
This is zero-copy; the returned Bytes uses the same underlying storage as the wrapped
Bytes object.
Sourcepub fn decode_all<T: Decode>(&mut self) -> Result<T, Error>
pub fn decode_all<T: Decode>(&mut self) -> Result<T, Error>
Convenience method to decode a value and ensure all bytes are consumed.
Trait Implementations§
Source§impl From<Bytes> for BytesCursor
impl From<Bytes> for BytesCursor
Source§impl Input for BytesCursor
impl Input for BytesCursor
Source§fn remaining_len(&mut self) -> Result<Option<usize>, Error>
fn remaining_len(&mut self) -> Result<Option<usize>, Error>
Should return the remaining length of the input data. If no information about the input
length is available,
None should be returned. Read moreSource§fn read(&mut self, into: &mut [u8]) -> Result<(), Error>
fn read(&mut self, into: &mut [u8]) -> Result<(), Error>
Read the exact number of bytes required to fill the given buffer. Read more
Source§fn descend_ref(&mut self) -> Result<(), Error>
fn descend_ref(&mut self) -> Result<(), Error>
Descend into nested reference when decoding.
This is called when decoding a new refence-based instance,
such as
Vec or Box. Currently, all such types are
allocated on the heap.Source§fn ascend_ref(&mut self)
fn ascend_ref(&mut self)
Ascend to previous structure level when decoding.
This is called when decoding reference-based type is finished.
impl LifetimeFree for BytesCursor
Auto Trait Implementations§
impl !Freeze for BytesCursor
impl RefUnwindSafe for BytesCursor
impl Send for BytesCursor
impl Sync for BytesCursor
impl Unpin for BytesCursor
impl UnsafeUnpin for BytesCursor
impl UnwindSafe for BytesCursor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> DecodeInto for Twhere
T: Input,
impl<T> DecodeInto for Twhere
T: Input,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more