Skip to main content

DynamicView

Struct DynamicView 

Source
pub struct DynamicView<'a, const N: usize> { /* private fields */ }
Expand description

An inline dynamic view that caches offsets for O(1) field access.

Created by walking the prefix bytes once, then all accessors use the cached offsets.

Generic over N = number of dynamic fields.

Implementations§

Source§

impl<'a, const N: usize> DynamicView<'a, N>

Source

pub fn parse( data: &'a [u8], base_offset: usize, prefix_sizes: &[u8; N], ) -> Result<Self, ProgramError>

Parse dynamic fields starting at base_offset in data.

prefix_sizes indicates prefix type per field: 1 = u8, 2 = u16, 4 = u32.

Source

pub fn field(&self, index: usize) -> &[u8]

Get the byte slice for dynamic field at index. O(1) after initial parse.

Source

pub fn field_len(&self, index: usize) -> usize

Get the length of dynamic field at index.

Source

pub fn field_as_str(&self, index: usize) -> Result<&str, ProgramError>

Try to interpret a dynamic field as a UTF-8 string.

Source

pub fn total_dynamic_bytes(&self) -> usize

Total bytes consumed by all dynamic fields (including prefixes).

Auto Trait Implementations§

§

impl<'a, const N: usize> Freeze for DynamicView<'a, N>

§

impl<'a, const N: usize> RefUnwindSafe for DynamicView<'a, N>

§

impl<'a, const N: usize> Send for DynamicView<'a, N>

§

impl<'a, const N: usize> Sync for DynamicView<'a, N>

§

impl<'a, const N: usize> Unpin for DynamicView<'a, N>

§

impl<'a, const N: usize> UnsafeUnpin for DynamicView<'a, N>

§

impl<'a, const N: usize> UnwindSafe for DynamicView<'a, N>

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.