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
sourceimpl<'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]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn remaining_slice(&self) -> &'a [u8]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [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
sourceimpl<'a> Ord for Bytes<'a>
impl<'a> Ord for Bytes<'a>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<'a> PartialOrd<Bytes<'a>> for Bytes<'a>
impl<'a> PartialOrd<Bytes<'a>> for Bytes<'a>
sourcefn partial_cmp(&self, other: &Bytes<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &Bytes<'a>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<'a> Copy for Bytes<'a>
impl<'a> Eq for Bytes<'a>
impl<'a> StructuralEq for Bytes<'a>
impl<'a> StructuralPartialEq for Bytes<'a>
Auto Trait Implementations
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
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