Expand description
Zero-copy row deserialization traits and utilities.
This module provides traits for efficient row deserialization that minimizes memory allocations by borrowing data directly from the database row.
§Zero-Copy Deserialization
The FromRowRef trait enables zero-copy deserialization for types that can
borrow string data directly from the row:
ⓘ
use prax_query::row::{FromRowRef, RowRef};
struct UserRef<'a> {
id: i32,
email: &'a str, // Borrowed from row
name: Option<&'a str>,
}
impl<'a> FromRowRef<'a> for UserRef<'a> {
fn from_row_ref(row: &'a impl RowRef) -> Result<Self, RowError> {
Ok(Self {
id: row.get("id")?,
email: row.get_str("email")?,
name: row.get_str_opt("name")?,
})
}
}§Performance
Zero-copy deserialization can significantly reduce allocations:
- String fields borrow directly from row buffer (no allocation)
- Integer/float fields are copied (no difference)
- Optional fields return
Option<&'a str>instead ofOption<String>
Structs§
- RowRef
Iter - A row iterator that yields zero-copy deserialized values.
Enums§
- RowData
- A collected result that can either borrow or own data.
- RowError
- Error type for row deserialization.
Traits§
- From
Column - Trait for types that can be extracted from a column.
- FromRow
- Trait for types that can be deserialized from a row (owning).
- From
RowRef - Trait for types that can be deserialized from a row reference (zero-copy).
- RowRef
- A database row that supports zero-copy access.