@@ -111,7 +111,8 @@ use crate::{error::Error, row::Row};
111
111
/// different placeholder values, if applicable.
112
112
///
113
113
/// This is similar to how `#[serde(default)]` behaves.
114
- /// ### `flatten`
114
+ ///
115
+ /// #### `flatten`
115
116
///
116
117
/// If you want to handle a field that implements [`FromRow`],
117
118
/// you can use the `flatten` attribute to specify that you want
@@ -177,33 +178,6 @@ use crate::{error::Error, row::Row};
177
178
/// assert!(user.addresses.is_empty());
178
179
/// ```
179
180
///
180
- /// ## Manual implementation
181
- ///
182
- /// You can also implement the [`FromRow`] trait by hand. This can be useful if you
183
- /// have a struct with a field that needs manual decoding:
184
- ///
185
- ///
186
- /// ```rust,ignore
187
- /// use sqlx::{FromRow, sqlite::SqliteRow, sqlx::Row};
188
- /// struct MyCustomType {
189
- /// custom: String,
190
- /// }
191
- ///
192
- /// struct Foo {
193
- /// bar: MyCustomType,
194
- /// }
195
- ///
196
- /// impl FromRow<'_, SqliteRow> for Foo {
197
- /// fn from_row(row: &SqliteRow) -> sqlx::Result<Self> {
198
- /// Ok(Self {
199
- /// bar: MyCustomType {
200
- /// custom: row.try_get("custom")?
201
- /// }
202
- /// })
203
- /// }
204
- /// }
205
- /// ```
206
- ///
207
181
/// #### `try_from`
208
182
///
209
183
/// When your struct contains a field whose type is not matched with the database type,
@@ -297,6 +271,33 @@ use crate::{error::Error, row::Row};
297
271
/// ```
298
272
/// Would describe a database field which _is_ NULLable but if it exists it must be the JSON representation of `Data`
299
273
/// and cannot be the JSON value `null`
274
+ ///
275
+ /// ## Manual implementation
276
+ ///
277
+ /// You can also implement the [`FromRow`] trait by hand. This can be useful if you
278
+ /// have a struct with a field that needs manual decoding:
279
+ ///
280
+ ///
281
+ /// ```rust,ignore
282
+ /// use sqlx::{FromRow, sqlite::SqliteRow, sqlx::Row};
283
+ /// struct MyCustomType {
284
+ /// custom: String,
285
+ /// }
286
+ ///
287
+ /// struct Foo {
288
+ /// bar: MyCustomType,
289
+ /// }
290
+ ///
291
+ /// impl FromRow<'_, SqliteRow> for Foo {
292
+ /// fn from_row(row: &SqliteRow) -> sqlx::Result<Self> {
293
+ /// Ok(Self {
294
+ /// bar: MyCustomType {
295
+ /// custom: row.try_get("custom")?
296
+ /// }
297
+ /// })
298
+ /// }
299
+ /// }
300
+ /// ```
300
301
pub trait FromRow < ' r , R : Row > : Sized {
301
302
fn from_row ( row : & ' r R ) -> Result < Self , Error > ;
302
303
}
0 commit comments