Struct spacetimedb_table::table::RowRef
source · pub struct RowRef<'a> { /* private fields */ }
Expand description
A reference to a single row within a table.
§Safety
Having a r: RowRef
is a proof that r.pointer()
refers to a valid row.
This makes constructing a RowRef
, i.e., RowRef::new
, an unsafe
operation.
Implementations§
source§impl<'a> RowRef<'a>
impl<'a> RowRef<'a>
sourcepub fn to_product_value(&self) -> ProductValue
pub fn to_product_value(&self) -> ProductValue
Extract a ProductValue
from the table.
This is a potentially expensive operation,
as it must walk the table’s ProductTypeLayout
and heap-allocate various substructures of the ProductValue
.
sourcepub fn read_col<T: ReadColumn>(
self,
col: impl Into<ColId>
) -> Result<T, TypeError>
pub fn read_col<T: ReadColumn>( self, col: impl Into<ColId> ) -> Result<T, TypeError>
Check that the idx
th column of the row type stored by self
is compatible with T
,
and read the value of that column from self
.
sourcepub fn project_not_empty(
self,
cols: &ColList
) -> Result<AlgebraicValue, InvalidFieldError>
pub fn project_not_empty( self, cols: &ColList ) -> Result<AlgebraicValue, InvalidFieldError>
Construct a projection of the row at self
by extracting the cols
.
Returns an error if cols
specifies an index which is out-of-bounds for the row at self
.
If cols
contains more than one column, the values of the projected columns are wrapped in a ProductValue
.
If cols
is a single column, the value of that column is returned without wrapping in a ProductValue
.
sourcepub fn pointer(&self) -> RowPointer
pub fn pointer(&self) -> RowPointer
Returns the raw row pointer for this row reference.
pub fn row_layout(&self) -> &RowTypeLayout
pub fn page_and_offset(&self) -> (&Page, PageOffset)
sourcepub fn bsatn_length(&self) -> Option<usize>
pub fn bsatn_length(&self) -> Option<usize>
The length of this row when BSATN-encoded.
Only available for rows whose types have a static BSATN layout.
Returns None
for rows of other types, e.g. rows containing strings.
sourcepub fn to_bsatn_vec(&self) -> Result<Vec<u8>, BsatnError>
pub fn to_bsatn_vec(&self) -> Result<Vec<u8>, BsatnError>
BSATN-encode the row referred to by self
into a freshly-allocated Vec<u8>
.
This method will use a StaticBsatnLayout
if one is available,
and may therefore be faster than calling bsatn::to_vec
.
sourcepub fn to_bsatn_extend(&self, buf: &mut Vec<u8>) -> Result<(), BsatnError>
pub fn to_bsatn_extend(&self, buf: &mut Vec<u8>) -> Result<(), BsatnError>
BSATN-encode the row referred to by self
into buf
,
pushing self
’s bytes onto the end of buf
, similar to Vec::extend
.
This method will use a StaticBsatnLayout
if one is available,
and may therefore be faster than calling bsatn::to_writer
.
Trait Implementations§
impl<'a> Copy for RowRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for RowRef<'a>
impl<'a> !RefUnwindSafe for RowRef<'a>
impl<'a> !Send for RowRef<'a>
impl<'a> !Sync for RowRef<'a>
impl<'a> Unpin for RowRef<'a>
impl<'a> !UnwindSafe for RowRef<'a>
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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Satn for T
impl<T> Satn for T
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
f
.source§fn fmt_psql(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt_psql(&self, f: &mut Formatter<'_>) -> Result<(), Error>
f
.source§fn to_satn(&self) -> String
fn to_satn(&self) -> String
String
.source§fn to_satn_pretty(&self) -> String
fn to_satn_pretty(&self) -> String
String
.