pub struct Bytes<'a> { /* private fields */ }
Expand description
A wrapper around &[u8]
to read more efficiently.
This has a specialized implementation of RmpWrite
and has error type Infallible.
This has the additional benefit of working on #[no_std]
(unlike the builtin Read trait)
See also serde_bytes::Bytes
Unlike a plain &[u8]
this also tracks an internal offset in the input (See Self::position
).
This is used for (limited) compatibility with std::io::Cursor
. Unlike a Cursor it does
not support mark/reset.
Implementations§
Source§impl<'a> Bytes<'a>
impl<'a> Bytes<'a>
Sourcepub fn new(bytes: &'a [u8]) -> Self
pub fn new(bytes: &'a [u8]) -> Self
Wrap an existing bytes slice.
This sets the internal position to zero.
Sourcepub fn remaining_slice(&self) -> &'a [u8] ⓘ
pub fn remaining_slice(&self) -> &'a [u8] ⓘ
Get a reference to the remaining bytes in the buffer.
Sourcepub fn position(&self) -> u64
pub fn position(&self) -> u64
Return the position of the input buffer.
This is not required for correctness, it only exists to help mimic
Cursor::position
Trait Implementations§
Source§impl<'a> Ord for Bytes<'a>
impl<'a> Ord for Bytes<'a>
Source§impl<'a> PartialOrd for Bytes<'a>
impl<'a> PartialOrd for Bytes<'a>
impl<'a> Copy for Bytes<'a>
impl<'a> Eq for Bytes<'a>
impl<'a> StructuralPartialEq for Bytes<'a>
Auto Trait Implementations§
impl<'a> Freeze for Bytes<'a>
impl<'a> RefUnwindSafe for Bytes<'a>
impl<'a> Send for Bytes<'a>
impl<'a> Sync for Bytes<'a>
impl<'a> Unpin for Bytes<'a>
impl<'a> UnwindSafe for Bytes<'a>
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