pub trait ZReaderTrait {
    // Required methods
    fn get_byte(&self, index: usize) -> Option<&u8>;
    fn get_slice(&self, index: Range<usize>) -> Option<&[u8]>;
    fn get_len(&self) -> usize;
}
Expand description

The underlying reader trait

Considerations

  • When implementing this for a type, it is recommended to implement methods with #inline[(always)] directive to allow the functions to get inlined in call sites, this may make it faster on some situations since the call sites may be in hot loop.

  • If you are reading from a file and it’s small , it is preferable to read it into memory instead of using a file reader.

Required Methods§

source

fn get_byte(&self, index: usize) -> Option<&u8>

Get a single byte which is at position index

Arguments
  • index: The position of the bytes
source

fn get_slice(&self, index: Range<usize>) -> Option<&[u8]>

Get a slice of bytes from a range of start..end

Arguments
  • index: The range of the bytes to read

returns: Option<&[u8]>

Examples
  • Read 10 bytes from
extern crate alloc;
use alloc::vec::Vec;
use zune_core::bytestream::ZReaderTrait;

let bytes = vec![0_u8;100];

// get ten bytes from 0..10
let re = bytes.get_slice(0..10).unwrap();
assert_eq!(10,re.len())
source

fn get_len(&self) -> usize

Get total length of the underlying buffer.

This should be the total bytes that are present in the buffer.

For files, this includes the file length. For buffers this includes the internal buffer length

Implementations on Foreign Types§

source§

impl ZReaderTrait for &Vec<u8>

source§

fn get_byte(&self, index: usize) -> Option<&u8>

source§

fn get_slice(&self, index: Range<usize>) -> Option<&[u8]>

source§

fn get_len(&self) -> usize

source§

impl ZReaderTrait for &[u8]

source§

fn get_byte(&self, index: usize) -> Option<&u8>

source§

fn get_slice(&self, index: Range<usize>) -> Option<&[u8]>

source§

fn get_len(&self) -> usize

source§

impl ZReaderTrait for Vec<u8>

source§

fn get_byte(&self, index: usize) -> Option<&u8>

source§

fn get_slice(&self, index: Range<usize>) -> Option<&[u8]>

source§

fn get_len(&self) -> usize

source§

impl ZReaderTrait for dyn AsRef<&[u8]>

source§

fn get_byte(&self, index: usize) -> Option<&u8>

source§

fn get_slice(&self, index: Range<usize>) -> Option<&[u8]>

source§

fn get_len(&self) -> usize

source§

impl<const N: usize> ZReaderTrait for &[u8; N]

source§

fn get_byte(&self, index: usize) -> Option<&u8>

source§

fn get_slice(&self, index: Range<usize>) -> Option<&[u8]>

source§

fn get_len(&self) -> usize

source§

impl<const N: usize> ZReaderTrait for [u8; N]

source§

fn get_byte(&self, index: usize) -> Option<&u8>

source§

fn get_slice(&self, index: Range<usize>) -> Option<&[u8]>

source§

fn get_len(&self) -> usize

Implementors§