pub struct Reader<'a> { /* private fields */ }
Expand description
§Safety
The caller is responsible for ensuring that the bytes slice is valid.
§Examples
use core::array;
use solana_bytes_reader::{Reader, ReadBytes};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let bytes: [u8; 32] = array::from_fn(|i| if i % 4 == 0 { i as u8 } else { 0u8 });
let mut reader: Reader = Reader::new(&bytes);
let first_u32: u32 = reader.read_u32()?;
let second_u32: u32 = reader.read_u32()?;
let third_u32: u32 = reader.read_u32()?;
assert_eq!(first_u32, 0u32);
assert_eq!(second_u32, 4u32);
assert_eq!(third_u32, 8u32);
Ok(())
}
It’s recommended to initialize Reader
and use it’s methods if there are more than 2 method calls.
Otherwise there’s no need in this struct and functions can be used instead.
Implementations§
Source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
Sourcepub fn new_with_offset(bytes: &'a [u8], offset: usize) -> Self
pub fn new_with_offset(bytes: &'a [u8], offset: usize) -> Self
§Panics
if offset
equals/greater than bytes slice OR if bytes slice is empty.
pub fn bytes(&self) -> &'a [u8] ⓘ
pub fn offset(&self) -> usize
Sourcepub fn set_offset(&mut self, new_offset: usize)
pub fn set_offset(&mut self, new_offset: usize)
§Panics
if new_offset
equals/greater than bytes slice.
Trait Implementations§
Source§impl PeekIntoBytes for Reader<'_>
impl PeekIntoBytes for Reader<'_>
type Error = ProgramError
Source§impl ReadBytes for Reader<'_>
impl ReadBytes for Reader<'_>
impl<'a> Copy for Reader<'a>
Auto Trait Implementations§
impl<'a> Freeze for Reader<'a>
impl<'a> RefUnwindSafe for Reader<'a>
impl<'a> Send for Reader<'a>
impl<'a> Sync for Reader<'a>
impl<'a> Unpin for Reader<'a>
impl<'a> UnwindSafe for Reader<'a>
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