pub trait FromRow: Sized {
// Required method
fn from_row(row: RowAccessor<'_>) -> Result<Self>;
}Expand description
Trait for types that can be constructed from a database row.
Used by Connection::fetch_one_as
and Connection::fetch_all_as
to map query results into typed structs. Implementations receive
a RowAccessor, which provides name-based
access via a column-name → index lookup built once per query.
§Recommended: derive
In most cases the #[derive(FromRow)] macro handles the mapping
for you — match struct field names to column names automatically,
with #[hyperdb(rename = "...")] for cases where they differ:
use hyperdb_api::FromRow;
use hyperdb_api_derive::FromRow; // proc-macro derive
#[derive(FromRow)]
struct User {
id: i32,
name: String,
#[hyperdb(rename = "email_address")]
email: Option<String>,
}§Hand-written impl
For custom mapping logic (computed fields, multi-column composition, etc.) implement the trait directly:
use hyperdb_api::{FromRow, RowAccessor, Result};
struct User { id: i32, name: String, active: bool }
impl FromRow for User {
fn from_row(row: RowAccessor<'_>) -> Result<Self> {
Ok(User {
id: row.get("id")?,
name: row.get("name")?,
active: row.get("active")?,
})
}
}For ad-hoc tuple destructuring of small results, use
Row::get directly — there are no blanket
tuple FromRow impls. Define a struct with #[derive(FromRow)]
for typed access in fetch_*_as.
Required Methods§
Sourcefn from_row(row: RowAccessor<'_>) -> Result<Self>
fn from_row(row: RowAccessor<'_>) -> Result<Self>
Constructs an instance from a database row.
§Errors
Returns an Error — typically
crate::Error::Column — when a required column is missing,
SQL NULL, or cannot be decoded as the expected type.
Implementations decide the exact failure shape.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".