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>
impl<'a, const N: usize> DynamicView<'a, N>
Sourcepub fn parse(
data: &'a [u8],
base_offset: usize,
prefix_sizes: &[u8; N],
) -> Result<Self, ProgramError>
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.
Sourcepub fn field(&self, index: usize) -> &[u8]
pub fn field(&self, index: usize) -> &[u8]
Get the byte slice for dynamic field at index. O(1) after initial parse.
Sourcepub fn field_as_str(&self, index: usize) -> Result<&str, ProgramError>
pub fn field_as_str(&self, index: usize) -> Result<&str, ProgramError>
Try to interpret a dynamic field as a UTF-8 string.
Sourcepub fn total_dynamic_bytes(&self) -> usize
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> 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