MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / read_column

Method read_column

crates/table/src/read_column.rs:141–168  ·  view source on GitHub ↗

Check that the `idx`th column of the row type stored by `row_ref` is compatible with `Self`, and read the value of that column from `row_ref`.

(row_ref: RowRef<'_>, idx: usize)

Source from the content-addressed store, hash-verified

139 /// Check that the `idx`th column of the row type stored by `row_ref` is compatible with `Self`,
140 /// and read the value of that column from `row_ref`.
141 fn read_column(row_ref: RowRef<'_>, idx: usize) -> Result<Self, TypeError> {
142 let layout = row_ref.row_layout().product();
143
144 // Look up the `ProductTypeElementLayout` of the requested column,
145 // or return an error on an out-of-bounds index.
146 let col = layout.elements.get(idx).ok_or_else(|| TypeError::IndexOutOfBounds {
147 desired: idx,
148 found: layout.product_type(),
149 })?;
150
151 // Check that the requested column is of the expected type.
152 if !Self::is_compatible_type(&col.ty) {
153 return Err(TypeError::WrongType {
154 desired: std::any::type_name::<Self>(),
155 found: col.ty.algebraic_type(),
156 });
157 }
158
159 Ok(unsafe {
160 // SAFETY:
161 // - We trust that the `row_ref.table` knows its own layout,
162 // and we've derived our type and layout info from it,
163 // so they are correct.
164 // - We trust `Self::is_compatible_type`, and it returned `true`,
165 // so the column must be of appropriate type.
166 Self::unchecked_read_column(row_ref, col)
167 })
168 }
169}
170
171unsafe impl ReadColumn for bool {

Callers

nothing calls this directly

Implementers 1

read_column.rscrates/table/src/read_column.rs

Calls 7

row_layoutMethod · 0.80
ErrFunction · 0.50
OkFunction · 0.50
productMethod · 0.45
getMethod · 0.45
product_typeMethod · 0.45
algebraic_typeMethod · 0.45

Tested by

no test coverage detected