Repository: diesel-rs/diesel
File: diesel/src/sqlite/expression/functions.rs (Rust)

Code before:
    /// assert_eq!(Some(false), result);
    ///
    /// // JSON5 valid with JSON5 flag (flag = 6)
    /// let result = diesel::select(json_valid_with_flags::<Text, _, _>(r#"{x:35}"#, 6))
    ///     .get_result::<Option<bool>>(connection)?;
    /// assert_eq!(Some(true), result);
    ///
    /// // Invalid JSON
    /// let result = diesel::select(json_valid_with_flags::<Text, _, _>(r#"{"x":35"#, 1))
    ///     .get_result::<Option<bool>>(connection)?;
    /// assert_eq!(Some(false), result);
    ///
    /// // NULL input returns NULL
    /// let result = diesel::select(json_valid_with_flags::<Nullable<Text>, _, _>(None::<&str>, 1))
    ///     .get_result::<Option<bool>>(connection)?;
    /// assert_eq!(None, result);
    ///
    /// # Ok(())
    /// # }
    /// ```
    #[sql_name = "json_valid"]
    #[cfg(feature = "sqlite")]
    fn json_valid_with_flags<X: TextOrNullableTextOrBinaryOrNullableBinary + SingleValue>(
        x: X,
        flags: Integer,
    ) -> Nullable<Bool>;

    /// The json_type(X) function returns the "type" of the outermost element of X.
    /// The "type" returned by json_type() is one of the following SQL text values:
    /// 'null', 'true', 'false', 'integer', 'real', 'text', 'array', or 'object'.
    ///
    /// This function requires at least SQLite 3.38 or newer
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     #[cfg(feature = "serde_json")]
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # #[cfg(feature = "serde_json")]
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::{sql, json_type};
    /// #     use serde_json::{json, Value};
    /// #     use diesel::sql_types::{Text, Json, Jsonb, Nullable};
    /// #     let connection = &mut establish_connection();
    /// #     assert_version!(connection, 3, 38, 0);
    ///

Review comment (suggestion):
I think we can make the return type not-nullable for not-nullable inports.

That would require:

1. Changing the bound to `X: TextOrNullableTextOrBinaryOrNullableBinary + SingleValue +  MaybeNullableValue<Bool>`
2. Changing the return type to `X::Out`
3. Changing the tests to use `bool` for non-nullable inputs

Code after:
    ///     .get_result::<bool>(connection)?;
    /// assert_eq!(false, result);
    ///
    /// // JSON5 valid with JSON5 flag
    /// let result = diesel::select(json_valid_with_flags::<Text, _, _>(r#"{x:35}"#, JsonValidFlag::Json5OrJsonb))
    ///     .get_result::<bool>(connection)?;
    /// assert_eq!(true, result);
    ///
    /// // Invalid JSON
    /// let result = diesel::select(json_valid_with_flags::<Text, _, _>(r#"{"x":35"#, JsonValidFlag::Rfc8259Json))
    ///     .get_result::<bool>(connection)?;
    /// assert_eq!(false, result);
    ///
    /// // NULL input returns NULL
    /// let result = diesel::select(json_valid_with_flags::<Nullable<Text>, _, _>(None::<&str>, JsonValidFlag::Rfc8259Json))
    ///     .get_result::<Option<bool>>(connection)?;
    /// assert_eq!(None, result);
    ///
    /// # Ok(())
    /// # }
    /// ```
    #[sql_name = "json_valid"]
    #[cfg(feature = "sqlite")]
    fn json_valid_with_flags<
        X: TextOrNullableTextOrBinaryOrNullableBinary + SingleValue + MaybeNullableValue<Bool>,
    >(
        x: X,
        flags: crate::sqlite::types::JsonValidFlags,
    ) -> X::Out;

    /// The json_type(X) function returns the "type" of the outermost element of X.
    /// The "type" returned by json_type() is one of the following SQL text values:
    /// 'null', 'true', 'false', 'integer', 'real', 'text', 'array', or 'object'.
    ///
    /// This function requires at least SQLite 3.38 or newer
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     #[cfg(feature = "serde_json")]
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # #[cfg(feature = "serde_json")]
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::{sql, json_type};
    /// #     use serde_json::{json, Value};
    /// #     use diesel::sql_types::{Text, Json, Jsonb, Nullable};