Skip to content

Commit 4d638c9

Browse files
authored
FromRow: Fix documentation order (#3712)
The `try_from` and `json` sections are "Field attributes" so they should probably be part of the corresponding section instead of subsections of "Manual implementation". `flatten` should be H4 instead of H3, since "Field attributes" is H3 and all other field attribute sections are H4 too.
1 parent 97cada3 commit 4d638c9

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

sqlx-core/src/from_row.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ use crate::{error::Error, row::Row};
111111
/// different placeholder values, if applicable.
112112
///
113113
/// This is similar to how `#[serde(default)]` behaves.
114-
/// ### `flatten`
114+
///
115+
/// #### `flatten`
115116
///
116117
/// If you want to handle a field that implements [`FromRow`],
117118
/// you can use the `flatten` attribute to specify that you want
@@ -177,33 +178,6 @@ use crate::{error::Error, row::Row};
177178
/// assert!(user.addresses.is_empty());
178179
/// ```
179180
///
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-
///
207181
/// #### `try_from`
208182
///
209183
/// 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};
297271
/// ```
298272
/// Would describe a database field which _is_ NULLable but if it exists it must be the JSON representation of `Data`
299273
/// 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+
/// ```
300301
pub trait FromRow<'r, R: Row>: Sized {
301302
fn from_row(row: &'r R) -> Result<Self, Error>;
302303
}

0 commit comments

Comments
 (0)