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

Code before:
    ///     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(())
    /// # }
    /// ```
    #[sql_name = "array_to_string"]
    fn array_to_string_with_null_string<Arr: ArrayOrNullableArray + SingleValue>(
        arr: Arr,
        delim: Text,
        null_str: Text
    ) -> Text;
}

#[cfg(feature = "postgres_backend")]
define_sql_function! {
    /// Converts each array element to its text representation, and concatenates those separated by the delimiter string.
    /// This variant omits the `null_str` argument. See [array_to_string_null] for a variant with that 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", "b", "c"], ","
    /// )).get_result::<String>(conn)?;
    /// assert_eq!("a, b, c".to_string(), result);
    ///
    /// #     Ok(())
    /// # }
    /// ```
    fn array_to_string<Arr: ArrayOrNullableArray + SingleValue>(
        arr: Arr,
        delim: Text
    ) -> Text;

Review comment (suggestion):
As you rename this function, new name should be used:
```suggestion
    /// This variant omits the `null_str` argument. See [`array_to_string_with_null_string`] for a variant with that argument
```

Code after:
    /// #    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)?;
    /// assert_eq!(vec![3, 1, 2], ints);
    ///
    /// let ints = diesel::select(array_prepend::<Nullable<Integer>, Array<_>, _, _>(None::<i32>, vec![Some(1), Some(2)]))
    ///     .get_result::<Vec<Option<i32>>>(connection)?;
    /// assert_eq!(vec![None, Some(1), Some(2)], ints);
    ///
    /// let ints = diesel::select(array_prepend::<Integer, Nullable<Array<_>>, _, _>(3, None::<Vec<i32>>))
    ///     .get_result::<Vec<i32>>(connection)?;