Skip to main content

RawView

Struct RawView 

Source
pub struct RawView<'a> {
    pub buf: &'a [u8],
    pub t_pos: usize,
    pub v_pos: usize,
}
Expand description

Low-level, type-erased view of a single table object.

Holds the three positions needed to navigate any table:

  • buf — the entire buffer the table lives in.
  • t_pos — absolute position of the table object (where the vtable jump is).
  • v_pos — absolute position of the vtable (computed from the jump).

All generated XxxView structs wrap a RawView as their inner field and delegate field lookups to its methods.

§Vtable navigation

t_pos → [vtable_jump: i32][field_0_data]...[field_n_data]

v_pos = t_pos - vtable_jump   (jump is negative when vtable is before table)

v_pos → [vtable_size: u16][object_size: u16]
         [voff_0: u16][voff_1: u16]...[voff_n: u16]

voff(i) == 0 means field i is absent (default value); non-zero means the field data starts at t_pos + voff(i).

Fields§

§buf: &'a [u8]§t_pos: usize

Absolute position of the table object’s first byte (the vtable jump).

§v_pos: usize

Absolute position of the vtable’s first byte.

Implementations§

Source§

impl<'a> RawView<'a>

Source

pub const EMPTY: RawView<'static>

Source

pub fn new(buf: &'a [u8], table_pos: usize) -> RawView<'a>

Construct a RawView given the absolute position of the table object.

The vtable position is computed by reading the signed 32-bit jump stored at table_pos: v_pos = table_pos - jump.

Source

pub fn from_slot(buf: &'a [u8], slot: usize) -> RawView<'a>

Construct from a slot (distance from the end of buf).

Converts slot → absolute position via buf.len() - slot, then delegates to new.

Source

pub fn voff(&self, field_idx: usize) -> usize

Read the vtable offset for field field_idx.

The vtable stores one u16 per field starting at v_pos + 4 (after the 2-byte vtable size and 2-byte object size). A value of 0 means the field is absent.

Source

pub fn is_present(&self, field_idx: usize) -> bool

Return true if field field_idx is present (vtable offset != 0).

Source

pub fn indirect_idx(&self, field_idx: usize) -> usize

Follow an Offset-mode field: read the forward offset at t_pos + voff(field_idx) and return the absolute position of the pointed-to data.

Source

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

Trait Implementations§

Source§

impl<'a> Clone for RawView<'a>

Source§

fn clone(&self) -> RawView<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Default for RawView<'a>

Source§

fn default() -> RawView<'a>

Returns the “default value” for a type. Read more
Source§

impl<'a> Copy for RawView<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for RawView<'a>

§

impl<'a> RefUnwindSafe for RawView<'a>

§

impl<'a> Send for RawView<'a>

§

impl<'a> Sync for RawView<'a>

§

impl<'a> Unpin for RawView<'a>

§

impl<'a> UnsafeUnpin for RawView<'a>

§

impl<'a> UnwindSafe for RawView<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.