Trait spacetimedb_table::var_len::VarLenMembers

source ·
pub unsafe trait VarLenMembers {
    type Iter<'this, 'row>: Iterator<Item = &'row MaybeUninit<VarLenRef>>
       where Self: 'this;
    type IterMut<'this, 'row>: Iterator<Item = &'row mut MaybeUninit<VarLenRef>>
       where Self: 'this;

    // Required methods
    unsafe fn visit_var_len_mut<'this, 'row>(
        &'this self,
        row: &'row mut Bytes
    ) -> Self::IterMut<'this, 'row>;
    unsafe fn visit_var_len<'this, 'row>(
        &'this self,
        row: &'row Bytes
    ) -> Self::Iter<'this, 'row>;
}
Expand description

A visitor object which can iterate over the var-len slots in a row.

Each var-len visitor is specialized to a particular row type, though implementors of VarLenMembers decide whether this specialization is per instance or per type.

The trivial implementor of VarLenMembers is AlignedVarLenOffsets, which stores the offsets of var-len members in a particular row type in a slice, and uses pointer arithmetic to return references to them.

§Safety

  • Self::visit_var_len and Self::visit_var_len_mut must visit the same set of VarLenRefs in the same order. Various consumers in Page and friends depend on this and the previous requirement.

Required Associated Types§

source

type Iter<'this, 'row>: Iterator<Item = &'row MaybeUninit<VarLenRef>> where Self: 'this

The iterator type returned by VarLenMembers::visit_var_len.

source

type IterMut<'this, 'row>: Iterator<Item = &'row mut MaybeUninit<VarLenRef>> where Self: 'this

The iterator type returned by VarLenMembers::visit_var_len_mut.

Required Methods§

source

unsafe fn visit_var_len_mut<'this, 'row>( &'this self, row: &'row mut Bytes ) -> Self::IterMut<'this, 'row>

Treats row as storage for a row of the particular type handled by self, and iterates over the (possibly uninitialized) VarLenRefs within it.

Callers are responsible for maintaining whether var-len members have been initialized.

§Safety
  • row must be properly aligned for the row type. This alignment constraint should be defined (and documented!) by the implementor of VarLenMembers.

  • row must further be a slice of exactly the number of bytes of the row type. Implementors may or may not check this property via debug_assert!, but callers must always ensure it for safety. These invariants allow us to construct references to VarLenRefs inside the slice.

    Note that Iterator::next is a safe function, so it must always be valid to advance an iterator to its end.

  • All callers of visit_var_len on a particular row must visit the same set of VarLenRefs in the same order, though they may do so through different implementors of VarLenMembers. E.g. it would be valid to use an AlignedVarLenOffsets to initialize a row, then later read from it using a hypothetical optimized JITted visitor, provided the JITted visitor visited the same set of offsets.

source

unsafe fn visit_var_len<'this, 'row>( &'this self, row: &'row Bytes ) -> Self::Iter<'this, 'row>

Treats row as storage for a row of the particular type handled by self, and iterates over the (possibly uninitialized) VarLenRefs within it.

Callers are responsible for maintaining whether var-len members have been initialized.

§Safety
  • row must be properly aligned for the row type. This alignment constraint should be defined (and documented!) by the implementor of VarLenMembers.

  • row must further be a slice of exactly the number of bytes of the row type. Implementors may or may not check this property via debug_assert!, but callers must always ensure it for safety. These invariants allow us to construct references to VarLenRefs inside the slice.

    Note that Iterator::next is a safe function, so it must always be valid to advance an iterator to it end.

  • All callers of visit_var_len on a particular row must visit the same set of VarLenRefs in the same order, though they may do so through different implementors of VarLenMembers. E.g. it would be valid to use an AlignedVarLenOffsets to initialize a row, then later read from it using a hypothetical optimized JITted visitor, provided the JITted visitor visited the same set of offsets.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl VarLenMembers for VarLenVisitorProgram

§

type Iter<'this, 'row> = VarLenVisitorProgramIter<'this, 'row>

§

type IterMut<'this, 'row> = VarLenVisitorProgramIterMut<'this, 'row>

source§

impl VarLenMembers for NullVarLenVisitor

§

type Iter<'this, 'row> = Empty<&'row MaybeUninit<VarLenRef>>

§

type IterMut<'this, 'row> = Empty<&'row mut MaybeUninit<VarLenRef>>

source§

impl<'a> VarLenMembers for AlignedVarLenOffsets<'a>

§

type Iter<'this, 'row> = AlignedVarLenOffsetsIter<'this, 'row> where Self: 'this

§

type IterMut<'this, 'row> = AlignedVarLenOffsetsIterMut<'this, 'row> where Self: 'this