Trait zune_core::bytestream::ZReaderTrait
source · 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§
sourcefn get_slice(&self, index: Range<usize>) -> Option<&[u8]>
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())