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

Code before:
    /// #
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::array_to_string_null;
    /// #     let conn = &mut establish_connection();
    ///
    /// let result_with_null_str = diesel::select(array_to_string_null::<Array<Text>, Text>(
    ///     vec!["a".to_string(), "b".to_string(), "c".to_string()],
    ///     ", ".to_string(),
    ///     Some("NULL".to_string())
    /// )).get_result::<String>(conn)?;
    /// assert_eq!("a, b, c".to_string(), result_with_null_str);
    ///
    /// let result_without_null_str = diesel::select(array_to_string_null::<Array<Text>, Text>(
    ///     vec!["a".to_string(), "b".to_string(), None],
    ///     ", ".to_string(),
    ///     None
    /// )).get_result::<String>(conn)?;
    /// assert_eq!("a, b".to_string(), result_without_null_str);
    ///
    /// #     Ok(())
    /// # }
    /// ```
    fn array_to_string_null<Arr: ArrayOrNullableArray<Inner=Elem> + SingleValue, Elem: SingleValue>(
        arr: Arr,
        delim: Text,
        null_str: Nullable<Text>
    ) -> Text;
}

#[cfg(feature = "postgres_backend")]
define_sql_function! {
    #[sql_name = "array_to_string"]
    /// Converts each array element to its text representation, and concatenates those separated by the delimiter string.
    /// This variant omits the `null_str` argument.
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::array_to_string;
    /// #     let conn = &mut establish_connection();
    ///
    /// let result = diesel::select(array_to_string::<Array<Text>, Text>(
    ///     vec!["a".to_string(), "b".to_string(), "c".to_string()],
    ///     ", ".to_string()
    /// )).get_result::<String>(conn)?;

Review comment (suggestion):
```suggestion
        null_str: Text
```

As we want to require that optional argument here

Code after:
    /// Returns a text representation of the array's dimensions
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main(){
    /// #    run_test().unwrap();
    /// # }
    /// # fn run_test()->QueryResult<()>{
    /// #   use diesel::dsl::array_dims;
    /// #   use diesel::sql_types::{Nullable,Array,Integer};
    /// #   let connection = &mut establish_connection();
    ///
    /// let dims = diesel::select(array_dims::<Array<Integer>,_>(vec![1,2]))
    ///     .get_result::<String>(connection)?;
    /// assert!(String::from("[1:2]").eq(&dims));
    ///
    /// let dims = diesel::select(array_dims::<Array<Nullable<Integer>>,_>(vec![None::<i32>,Some(2)]))
    ///     .get_result::<String>(connection)?;
    /// assert!(String::from("[1:2]").eq(&dims));
    ///
    /// let dims = diesel::select(array_dims::<Array<Nullable<Integer>>,_>(vec![None::<i32>]))
    ///     .get_result::<String>(connection)?;
    /// assert!(String::from("[1:1]").eq(&dims));
    /// # Ok(())
    /// # }
    ///
    fn array_dims<Arr:ArrayOrNullableArray<> + SingleValue>(arr:Arr) -> Text;
}

#[cfg(feature = "postgres_backend")]
define_sql_function! {
    /// Prepends an element to the beginning of an array
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::array_prepend;
    /// #     use diesel::sql_types::{Nullable, Integer, Array};
    /// #     let connection = &mut establish_connection();
    /// let ints = diesel::select(array_prepend::<Integer, Array<_>, _, _>(3, vec![1, 2]))
    ///     .get_result::<Vec<i32>>(connection)?;