pub struct SliceReader<'de> { /* private fields */ }Expand description
An efficient Reader wrapper around a slice.
Implementations§
Source§impl<'de> SliceReader<'de>
impl<'de> SliceReader<'de>
Sourcepub fn as_slice(&self) -> &'de [u8] ⓘ
pub fn as_slice(&self) -> &'de [u8] ⓘ
Get the remaining contents of the reader as a slice.
§Examples
use musli::Context;
use musli::reader::{Reader, SliceReader};
fn process<C>(cx: C) -> Result<(), C::Error>
where
C: Context
{
let mut reader = SliceReader::new(&[1, 2, 3, 4]);
assert_eq!(reader.as_slice(), &[1, 2, 3, 4]);
reader.skip(cx, 2)?;
assert_eq!(reader.as_slice(), &[3, 4]);
Ok(())
}Sourcepub fn remaining(&self) -> usize
pub fn remaining(&self) -> usize
Get remaining bytes in the reader.
§Examples
use musli::Context;
use musli::reader::{Reader, SliceReader};
fn process<C>(cx: C) -> Result<(), C::Error>
where
C: Context
{
let mut reader = SliceReader::new(&[1, 2, 3, 4]);
assert_eq!(reader.remaining(), 4);
reader.skip(cx, 2);
assert_eq!(reader.remaining(), 2);
Ok(())
}Trait Implementations§
Source§impl<'de> Reader<'de> for SliceReader<'de>
impl<'de> Reader<'de> for SliceReader<'de>
Source§type Mut<'this> = &'this mut SliceReader<'de>
where
Self: 'this
type Mut<'this> = &'this mut SliceReader<'de> where Self: 'this
Type borrowed from self. Read more
Source§type TryClone = SliceReader<'de>
type TryClone = SliceReader<'de>
Type that can be cloned from the reader.
Source§fn borrow_mut(&mut self) -> Self::Mut<'_>
fn borrow_mut(&mut self) -> Self::Mut<'_>
Borrow the current reader.
Source§fn skip<C>(&mut self, cx: C, n: usize) -> Result<(), C::Error>where
C: Context,
fn skip<C>(&mut self, cx: C, n: usize) -> Result<(), C::Error>where
C: Context,
Skip over the given number of bytes.
Source§fn read_bytes<C, V>(
&mut self,
cx: C,
n: usize,
visitor: V,
) -> Result<V::Ok, V::Error>
fn read_bytes<C, V>( &mut self, cx: C, n: usize, visitor: V, ) -> Result<V::Ok, V::Error>
Read a slice out of the current reader.
Source§unsafe fn read_bytes_uninit<C>(
&mut self,
cx: C,
ptr: *mut u8,
n: usize,
) -> Result<(), C::Error>where
C: Context,
unsafe fn read_bytes_uninit<C>(
&mut self,
cx: C,
ptr: *mut u8,
n: usize,
) -> Result<(), C::Error>where
C: Context,
Read into the given buffer which might not have been initialized. Read more
Source§fn read<C>(&mut self, cx: C, buf: &mut [u8]) -> Result<(), C::Error>where
C: Context,
fn read<C>(&mut self, cx: C, buf: &mut [u8]) -> Result<(), C::Error>where
C: Context,
Read a slice into the given buffer.
Source§fn read_byte<C>(&mut self, cx: C) -> Result<u8, C::Error>where
C: Context,
fn read_byte<C>(&mut self, cx: C) -> Result<u8, C::Error>where
C: Context,
Read a single byte.
impl Send for SliceReader<'_>
impl Sync for SliceReader<'_>
Auto Trait Implementations§
impl<'de> Freeze for SliceReader<'de>
impl<'de> RefUnwindSafe for SliceReader<'de>
impl<'de> Unpin for SliceReader<'de>
impl<'de> UnwindSafe for SliceReader<'de>
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