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

Code before:
    ///         json!([{"odd":[2,4,6,8]}]),
    ///         // not vec!["odd"], cannot set path in scalar
    ///         vec!["0","odd"],
    ///         json!([1,3,5,7])
    ///     )).get_result::<Value>(connection)?;
    /// let expected: Value = json!([{"odd":[1,3,5,7]}]);
    /// assert_eq!(result, expected);
    ///
    /// let empty:Vec<String> = Vec::new();
    /// let result = diesel::select(jsonb_set::<Nullable<Jsonb>, Array<Nullable<Text>>, _, _, _>(
    ///         None::<Value>,
    ///         empty,
    ///         None::<Value>
    ///     )).get_result::<Option<Value>>(connection)?;
    /// assert!(result.is_none());
    ///
    /// let empty:Vec<String> = Vec::new();
    /// let result = diesel::select(jsonb_set::<Jsonb, Array<Nullable<Text>>, _, _, _>(
    ///         // cannot be json!(null)
    ///         json!([]),
    ///         empty,
    ///         json!(null)
    ///     )).get_result::<Value>(connection)?;
    /// let expected = json!([]);
    /// assert_eq!(result, expected);
    ///
    ///
    ///
    /// #     Ok(())
    /// # }
    /// ```
    fn jsonb_set<
        E: JsonbOrNullableJsonb + SingleValue,
        Arr: TextArrayOrNullableTextArray + SingleValue
    >(base: E, path: Arr, new_value: E) -> E;
}


Review comment (suggestion):
I'm sorry to bring that up, but the following example won't infer nullablity correctly:

```rust
    /// let result = diesel::select(jsonb_set::<Jsonb, Nullable<Array<Nullable<Text>>>, _, _, _>(
    ///         // cannot be json!(null)
    ///         json!([]),
    ///         None,
    ///         json!({"foo": 42})
    ///     )).get_result::<Value>(connection)?;
```

This is expected to only accept a `Option<Value>` as return type as the return value will be `NULL` in this case.

Code after:
    ///         json!([{"odd":[2,4,6,8]}]),
    ///         // not vec!["odd"], cannot set path in scalar
    ///         vec!["0","odd"],
    ///         json!([1,3,5,7])
    ///     )).get_result::<Value>(connection)?;
    /// let expected: Value = json!([{"odd":[1,3,5,7]}]);
    /// assert_eq!(result, expected);
    ///
    /// let empty:Vec<String> = Vec::new();
    /// let result = diesel::select(jsonb_set::<Nullable<Jsonb>, Array<Nullable<Text>>, _, _, _>(
    ///         None::<Value>,
    ///         empty,
    ///         None::<Value>
    ///     )).get_result::<Option<Value>>(connection)?;
    /// assert!(result.is_none());
    ///
    /// let empty:Vec<String> = Vec::new();
    /// let result = diesel::select(jsonb_set::<Jsonb, Array<Nullable<Text>>, _, _, _>(
    ///         // cannot be json!(null)
    ///         json!([]),
    ///         empty,
    ///         json!(null)
    ///     )).get_result::<Value>(connection)?;
    /// let expected = json!([]);
    /// assert_eq!(result, expected);
    ///
    /// let result = diesel::select(jsonb_set::<Jsonb, Nullable<Array<Nullable<Text>>>, _, _, _,>(
    ///         json!(null),
    ///         None::<Vec<String>>,
    ///         json!({"foo": 42})
    ///     )).get_result::<Option<Value>>(connection)?;
    /// assert!(result.is_none());
    ///
    ///
    /// #     Ok(())
    /// # }
    /// ```
    fn jsonb_set<
        E: JsonbOrNullableJsonb + SingleValue,
        Arr: TextArrayOrNullableTextArray + CombinedNullableValue<E,Jsonb>
    >(base: E, path: Arr, new_value: E) -> Arr::Out;
}