diff --git a/sqlx-core/src/from_row.rs b/sqlx-core/src/from_row.rs index a71b40af..050fa106 100644 --- a/sqlx-core/src/from_row.rs +++ b/sqlx-core/src/from_row.rs @@ -122,6 +122,33 @@ use crate::row::Row; /// ``` /// /// This field is compatible with the `default` attribute. +/// +/// ## Manual implementation +/// +/// You can also implement the [`FromRow`] trait by hand. This can be useful if you +/// have a struct with a field that needs manuel decoding: +/// +/// +/// ```rust,ignore +/// use sqlx::{FromRow, sqlite::SqliteRow, sqlx::Row}; +/// struct MyCustomType { +/// custom: String, +/// } +/// +/// struct Foo { +/// bar: MyCustomType, +/// } +/// +/// impl FromRow<'_, SqliteRow> for Foo { +/// fn from_row(row: &SqliteRow) -> sqlx::Result { +/// Ok(Self { +/// bar: MyCustomType { +/// custom: row.try_get("custom")? +/// } +/// }) +/// } +/// } +/// ``` pub trait FromRow<'r, R: Row>: Sized { fn from_row(row: &'r R) -> Result; }