Skip to main content

SegmentTable

Struct SegmentTable 

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

Immutable view over the segment table region of an account.

The table starts at a known offset (typically right after the fixed prefix) and contains segment_count descriptors of 8 bytes each.

Implementations§

Source§

impl<'a> SegmentTable<'a>

Source

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

Parse a segment table from data.

data should start at the first descriptor byte. segment_count must be ≤ MAX_SEGMENTS.

Source

pub fn len(&self) -> usize

Number of segments in the table.

Source

pub fn is_empty(&self) -> bool

Whether the table has no segments.

Source

pub fn descriptor( &self, index: usize, ) -> Result<SegmentDescriptor, ProgramError>

Get the descriptor at index.

Source

pub fn validate( &self, account_len: usize, expected_sizes: &[u16], min_offset: usize, ) -> Result<(), ProgramError>

Validate that all segments are well-formed within account_len bytes.

min_offset is the earliest byte at which segment data may start (typically DATA_START_OFFSET - after the fixed prefix + table). This prevents segment data from overlapping the fixed prefix or the segment table itself.

Checks:

  • Element size matches expected_sizes[i] (if provided).
  • Segment data fits within the account.
  • No segment data starts before min_offset.
  • No two segments overlap.
  • All segments are ordered by offset.
Source

pub fn byte_len(&self) -> usize

Total byte size of the table itself (segment_count × 8).

Auto Trait Implementations§

§

impl<'a> Freeze for SegmentTable<'a>

§

impl<'a> RefUnwindSafe for SegmentTable<'a>

§

impl<'a> Send for SegmentTable<'a>

§

impl<'a> Sync for SegmentTable<'a>

§

impl<'a> Unpin for SegmentTable<'a>

§

impl<'a> UnsafeUnpin for SegmentTable<'a>

§

impl<'a> UnwindSafe for SegmentTable<'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.