pub trait RefFromRow<'buf>: Sized {
// Required method
fn ref_from_row(
cols: &[ColumnDefinition<'_>],
row: BinaryRowPayload<'buf>,
) -> Result<&'buf Self>;
}Expand description
Trait for zero-copy decoding of a row into a fixed-size struct.
Unlike FromRow, this trait returns a reference directly into the buffer
without any copying or allocation. This requires:
- All fields have fixed wire sizes (implement
FixedWireSize) - No NULL values (columns must be
NOT NULL) - Struct has
#[repr(C, packed)]layout
The derive macro generates zerocopy trait implementations automatically.
Required Methods§
Sourcefn ref_from_row(
cols: &[ColumnDefinition<'_>],
row: BinaryRowPayload<'buf>,
) -> Result<&'buf Self>
fn ref_from_row( cols: &[ColumnDefinition<'_>], row: BinaryRowPayload<'buf>, ) -> Result<&'buf Self>
Decode a row as a zero-copy reference.
§Errors
Returns an error if:
- The row data size doesn’t match the struct size
- Any column is NULL (RefFromRow doesn’t support NULL)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.