Repository: diesel-rs/diesel
File: diesel/src/deserialize.rs (Rust)

Code before:
use crate::sql_types::{SingleValue, SqlType, Untyped};
use crate::Selectable;

/// A specialized result type representing the result of deserializing
/// a value from the database.
pub type Result<T> = result::Result<T, Box<dyn Error + Send + Sync>>;

/// Trait indicating that a record can be queried from the database.
///
/// Types which implement `Queryable` represent the result of a SQL query. This
/// does not necessarily mean they represent a single database table.
///
/// Diesel represents the return type of a query as a tuple. The purpose of this
/// trait is to convert from a tuple of Rust values that have been deserialized
/// into your struct.
///
/// This trait can be [derived](derive@Queryable)
///
/// ## How to resolve compiler errors while loading data from the database
///
/// In case you getting uncomprehensable compiler errors while loading data
/// from the database you might want to consider using
/// [`#[derive(Selectable)]`](derive@crate::prelude::Selectable) +
/// `#[diesel(check_for_backend(YourBackendType))]` to check for mismatching fields at compile
/// time. This drastically improves the quality of the generated error messages by pointing
/// to concrete mismatches at field level.
///
/// ## Interaction with `NULL`/`Option`
/// [`Nullable`][crate::sql_types::Nullable] types can be queried into `Option`.
/// This is valid for single fields, tuples, and structures with `Queryable`.
///
/// With tuples and structs, the process for deserializing an `Option<(A,B,C)>` is
/// to attempt to deserialize `A`, `B` and `C`, and if either of these return an
/// [`UnexpectedNullError`](crate::result::UnexpectedNullError), the `Option` will be
/// deserialized as `None`.  
/// If all succeed, the `Option` will be deserialized as `Some((a,b,c))`.
///
/// # Examples
///
/// ## Simple mapping from query to struct
///
/// If we just want to map a query to our struct, we can use `derive`.
///
/// ```rust
/// # include!("doctest_setup.rs");
/// #
/// #[derive(Queryable, PartialEq, Debug)]
/// struct User {
///     id: i32,
///     name: String,
/// }

Review comment (suggestion):
I think, you also should describe downsides of this approach, otherwise it is unclear, why you need to manually enable great compiler messages. Also, it is unclear why the user should specify backend, because the struct is the same for all backends and isn't depend on them.

It would also be useful, if you include the example of the generated code that implements the check, maybe under the implementation note heading.

Code after:
use crate::sql_types::{SingleValue, SqlType, Untyped};
use crate::Selectable;

/// A specialized result type representing the result of deserializing
/// a value from the database.
pub type Result<T> = result::Result<T, Box<dyn Error + Send + Sync>>;

/// Trait indicating that a record can be queried from the database.
///
/// Types which implement `Queryable` represent the result of a SQL query. This
/// does not necessarily mean they represent a single database table.
///
/// Diesel represents the return type of a query as a tuple. The purpose of this
/// trait is to convert from a tuple of Rust values that have been deserialized
/// into your struct.
///
/// This trait can be [derived](derive@Queryable)
///
/// ## How to resolve compiler errors while loading data from the database
///
/// In case you getting uncomprehensable compiler errors while loading data
/// from the database you might want to consider using
/// [`#[derive(Selectable)]`](derive@crate::prelude::Selectable) +
/// `#[diesel(check_for_backend(YourBackendType))]` to check for mismatching fields at compile
/// time. This drastically improves the quality of the generated error messages by pointing
/// to concrete mismatches at field level. You need to specify the concrete database backend
/// this specific struct is indented to be used with, as otherwise rustc cannot correctly
/// identify the required deserialization implementation.
///
/// ## Interaction with `NULL`/`Option`
/// [`Nullable`][crate::sql_types::Nullable] types can be queried into `Option`.
/// This is valid for single fields, tuples, and structures with `Queryable`.
///
/// With tuples and structs, the process for deserializing an `Option<(A,B,C)>` is
/// to attempt to deserialize `A`, `B` and `C`, and if either of these return an
/// [`UnexpectedNullError`](crate::result::UnexpectedNullError), the `Option` will be
/// deserialized as `None`.  
/// If all succeed, the `Option` will be deserialized as `Some((a,b,c))`.
///
/// # Examples
///
/// ## Simple mapping from query to struct
///
/// If we just want to map a query to our struct, we can use `derive`.
///
/// ```rust
/// # include!("doctest_setup.rs");
/// #
/// #[derive(Queryable, PartialEq, Debug)]
/// struct User {
///     id: i32,