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

Code before:
}

/// Allow ~type inference on [And](crate::helper_types::And) and [Or](crate::helper_types::Or)
/// helper types
///
/// This is used to be statistically correct as last generic parameter of `dsl::And` and `dsl::Or`
/// without having to specify an additional type parameter.
///
/// It works with types that are [Expression]s and have a [`SqlType`](Expression::SqlType) that is
/// either [`Bool`](sql_types::Bool) or [`Nullable<Bool>`](sql_types::Nullable), and with [`bool`]
/// (and `Option<bool>` and references to those).
///
/// Cases where an additional type parameter would still have to be specified in the helper type
/// generic parameters are:
/// - If this trait isn't implemented for the `other` parameter of the expression
///   (in that case the user (you?) probably wants to implement it)
/// - If the user actually was using the not-preferred implementation of `AsExpression`
///   (e.g. towards `Nullable<Bool>` instead of `Bool`)
pub trait PreferredBoolSqlType {
    /// The preferred `Bool` SQL type for this AsExpression implementation.
    ///
    /// That should be either `Bool` or `Nullable<Bool>`.
    type PreferredSqlType;
}
impl<E: Expression> PreferredBoolSqlType for E
where
    E::SqlType: BoolOrNullableBool,
{
    type PreferredSqlType = <E as Expression>::SqlType;
}
/// This impl has to live in Diesel because otherwise it would conflict with the blanket impl above
/// because "diesel might add an implementation of Expression for bool"
impl PreferredBoolSqlType for bool {
    type PreferredSqlType = sql_types::Bool;
}
impl PreferredBoolSqlType for &bool {
    type PreferredSqlType = sql_types::Bool;
}
impl PreferredBoolSqlType for &&bool {
    type PreferredSqlType = sql_types::Bool;
}
impl PreferredBoolSqlType for Option<bool> {
    type PreferredSqlType = sql_types::Nullable<sql_types::Bool>;
}
impl PreferredBoolSqlType for &Option<bool> {
    type PreferredSqlType = sql_types::Nullable<sql_types::Bool>;
}
impl PreferredBoolSqlType for &&Option<bool> {
    type PreferredSqlType = sql_types::Nullable<sql_types::Bool>;
}


Review comment (suggestion):
```suggestion

impl<E: Expression> PreferredBoolSqlType for E
```

Code after:
}

/// Allow ~type inference on [And](crate::helper_types::And) and [Or](crate::helper_types::Or)
/// helper types
///
/// This is used to be statistically correct as last generic parameter of `dsl::And` and `dsl::Or`
/// without having to specify an additional type parameter.
///
/// It works with types that are [Expression]s and have a [`SqlType`](Expression::SqlType) that is
/// either [`Bool`](sql_types::Bool) or [`Nullable<Bool>`](sql_types::Nullable), and with [`bool`]
/// (and `Option<bool>` and references to those).
///
/// Cases where an additional type parameter would still have to be specified in the helper type
/// generic parameters are:
/// - If this trait isn't implemented for the `other` parameter of the expression
///   (in that case the user (you?) probably wants to implement it)
/// - If the user actually was using the not-preferred implementation of `AsExpression`
///   (e.g. towards `Nullable<Bool>` instead of `Bool`)
pub trait PreferredBoolSqlType {
    /// The preferred `Bool` SQL type for this AsExpression implementation.
    ///
    /// That should be either `Bool` or `Nullable<Bool>`.
    type PreferredSqlType;
}

impl<E: Expression> PreferredBoolSqlType for E
where
    E::SqlType: BoolOrNullableBool,
{
    type PreferredSqlType = <E as Expression>::SqlType;
}

/// This impl has to live in Diesel because otherwise it would conflict with the blanket impl above
/// because "diesel might add an implementation of Expression for bool"
impl PreferredBoolSqlType for bool {
    type PreferredSqlType = sql_types::Bool;
}

impl PreferredBoolSqlType for &bool {
    type PreferredSqlType = sql_types::Bool;
}

impl PreferredBoolSqlType for &&bool {
    type PreferredSqlType = sql_types::Bool;
}

impl PreferredBoolSqlType for Option<bool> {
    type PreferredSqlType = sql_types::Nullable<sql_types::Bool>;
}

impl PreferredBoolSqlType for &Option<bool> {