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>
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>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
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 more
impl<'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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more