Skip to main content

RefFromRow

Trait RefFromRow 

Source
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:

  1. All fields have fixed wire sizes (implement FixedWireSize)
  2. No NULL values (columns must be NOT NULL)
  3. Struct has #[repr(C, packed)] layout

The derive macro generates zerocopy trait implementations automatically.

Required Methods§

Source

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.

Implementors§