Skip to main content

SliceCursor

Struct SliceCursor 

Source
pub struct SliceCursor<'a> { /* private fields */ }
Expand description

Sequential read cursor over a byte slice.

Tracks a position and provides typed reads that advance it. Used for parsing instruction data and reading account fields sequentially.

Implementations§

Source§

impl<'a> SliceCursor<'a>

Source

pub const fn new(data: &'a [u8]) -> Self

Create a new cursor at position 0.

Source

pub fn from_instruction( data: &'a [u8], min_len: usize, ) -> Result<Self, ProgramError>

Create a cursor from instruction data, validating minimum length.

Source

pub const fn position(&self) -> usize

Current byte position.

Source

pub const fn remaining(&self) -> usize

Remaining bytes after current position.

Source

pub fn data_from_position(&self) -> &'a [u8]

Reference to remaining data from current position.

Source

pub fn skip(&mut self, n: usize) -> Result<(), ProgramError>

Skip n bytes forward.

Source

pub fn read_u8(&mut self) -> Result<u8, ProgramError>

Read a u8 and advance.

Source

pub fn read_u16(&mut self) -> Result<u16, ProgramError>

Read a little-endian u16 and advance.

Source

pub fn read_u32(&mut self) -> Result<u32, ProgramError>

Read a little-endian u32 and advance.

Source

pub fn read_u64(&mut self) -> Result<u64, ProgramError>

Read a little-endian u64 and advance.

Source

pub fn read_i64(&mut self) -> Result<i64, ProgramError>

Read a little-endian i64 and advance.

Source

pub fn read_bool(&mut self) -> Result<bool, ProgramError>

Read a boolean (0 = false, non-zero = true) and advance.

Source

pub fn read_address(&mut self) -> Result<&'a [u8; 32], ProgramError>

Read a 32-byte address and advance.

Source

pub fn read_bytes(&mut self, len: usize) -> Result<&'a [u8], ProgramError>

Read a fixed-size byte array and advance.

Auto Trait Implementations§

§

impl<'a> Freeze for SliceCursor<'a>

§

impl<'a> RefUnwindSafe for SliceCursor<'a>

§

impl<'a> Send for SliceCursor<'a>

§

impl<'a> Sync for SliceCursor<'a>

§

impl<'a> Unpin for SliceCursor<'a>

§

impl<'a> UnsafeUnpin for SliceCursor<'a>

§

impl<'a> UnwindSafe for SliceCursor<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.