Trait spacetimedb_table::var_len::VarLenMembers
source · pub unsafe trait VarLenMembers {
type Iter<'this, 'row>: Iterator<Item = &'row VarLenRef>
where Self: 'this;
type IterMut<'this, 'row>: Iterator<Item = &'row mut 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
andSelf::visit_var_len_mut
must visit the same set ofVarLenRef
s in the same order. Various consumers inPage
and friends depend on this and the previous requirement.
Required Associated Types§
sourcetype Iter<'this, 'row>: Iterator<Item = &'row VarLenRef>
where
Self: 'this
type Iter<'this, 'row>: Iterator<Item = &'row VarLenRef> where Self: 'this
The iterator type returned by VarLenMembers::visit_var_len
.
sourcetype IterMut<'this, 'row>: Iterator<Item = &'row mut VarLenRef>
where
Self: 'this
type IterMut<'this, 'row>: Iterator<Item = &'row mut VarLenRef> where Self: 'this
The iterator type returned by VarLenMembers::visit_var_len_mut
.
Required Methods§
sourceunsafe fn visit_var_len_mut<'this, 'row>(
&'this self,
row: &'row mut Bytes,
) -> Self::IterMut<'this, 'row>
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 stale) VarLenRef
s within it.
Visited VarLenRef
s are valid-unconstrained
and will always be valid from Rust/LLVM’s perspective,
i.e. will never be uninit,
but will not necessarily point to properly-allocated VarLenGranule
s.
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 ofVarLenMembers
. -
row
must further be a slice of exactly the number of bytes of the row type. Implementors may or may not check this property viadebug_assert!
, but callers must always ensure it for safety. These invariants allow us to construct references toVarLenRef
s 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 particularrow
must visit the same set ofVarLenRef
s in the same order, though they may do so through different implementors ofVarLenMembers
. E.g. it would be valid to use anAlignedVarLenOffsets
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.
sourceunsafe fn visit_var_len<'this, 'row>(
&'this self,
row: &'row Bytes,
) -> Self::Iter<'this, 'row>
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 stale) VarLenRef
s within it.
Visited VarLenRef
s are valid-unconstrained
and will always be valid from Rust/LLVM’s perspective,
i.e. will never be uninit,
but will not necessarily point to properly-allocated VarLenGranule
s.
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 ofVarLenMembers
. -
row
must further be a slice of exactly the number of bytes of the row type. Implementors may or may not check this property viadebug_assert!
, but callers must always ensure it for safety. These invariants allow us to construct references toVarLenRef
s 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 particularrow
must visit the same set ofVarLenRef
s in the same order, though they may do so through different implementors ofVarLenMembers
. E.g. it would be valid to use anAlignedVarLenOffsets
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.