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

Code before:
    /// #    run_test().unwrap();
    /// # }
    /// # fn run_test()->QueryResult<()>{
    /// #   use diesel::dsl::array_fill;
    /// #   use diesel::sql_types::{Nullable,Array,Integer,Text};
    /// #   let connection = &mut establish_connection();
    ///
    /// let array = diesel::select(array_fill::<Integer,_,_>(2,vec![2]))
    /// .get_result::<Vec<i32>>(connection)?;
    /// assert_eq!(vec![2,2],array);
    ///
    /// let array = diesel::select(array_fill::<Text,_,_>(String::from("abc"),vec![3]))
    /// .get_result::<Vec<String>>(connection)?;
    /// assert_eq!(vec!["abc","abc","abc"],array);
    ///
    /// let array = diesel::select(array_fill::<Nullable<Integer>,_,_>(Some(4),vec![3]))
    /// .get_result::<Vec<Option<i32>>>(connection)?;
    /// assert_eq!(vec![Some(4),Some(4),Some(4)],array);
    ///
    /// let array = diesel::select(array_fill::<Nullable<Integer>,_,_>(None::<i32>,vec![3]))
    /// .get_result::<Vec<Option<i32>>>(connection)?;
    /// assert_eq!(vec![None::<i32>,None::<i32>,None::<i32>],array);
    /// # Ok(())
    /// # }
    ///
    fn array_fill<E:SingleValue>(value:E,dim:Array<Integer>) -> Array<E>;
}

#[cfg(feature = "postgres_backend")]
define_sql_function! {
    /// Returns an array initialized with supplied value and dimensions,
    /// with lower bounds other than 1
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main(){
    /// #    run_test().unwrap();
    /// # }
    /// # fn run_test()->QueryResult<()>{
    /// #   use diesel::dsl::array_fill_with_lower_bound;
    /// #   use diesel::sql_types::{Nullable,Array,Integer,Text};
    /// #   let connection = &mut establish_connection();
    ///
    /// let array = diesel::select(array_fill_with_lower_bound::<Integer,_,_,_>(2,vec![2],vec![2]))
    /// .get_result::<Vec<i32>>(connection)?;
    /// assert_eq!(vec![2,2],array);
    ///
    /// let array = diesel::select(array_fill_with_lower_bound::<Text,_,_,_>(String::from("abc"),vec![3],vec![3]))

Review comment (suggestion):
```suggestion
    fn array_fill<E:SingleValue>(value: E, dim: Array<Integer>) -> Array<E>;
```

Code after:
    /// # fn run_test()->QueryResult<()>{
    /// #   use diesel::dsl::trim_array;
    /// #   use diesel::sql_types::{Nullable,Array,Integer};
    /// #   let connection = &mut establish_connection();
    ///
    /// let trimmed_array = diesel::select(trim_array::<Array<Integer>, _, _>(vec![1, 2, 3, 4], 3))
    ///     .get_result::<Vec<i32>>(connection)?;
    /// assert_eq!(vec![1], trimmed_array);
    ///
    /// let trimmed_array = diesel::select(trim_array::<Array<Nullable<Integer>>, _, _>(vec![Some(1), Some(2), Some(3)], 1))
    ///     .get_result::<Vec<Option<i32>>>(connection)?;
    /// assert_eq!(vec![Some(1), Some(2)], trimmed_array);
    ///
    /// let trimmed_array = diesel::select(trim_array::<Array<Integer>, _, _>(Vec::<i32>::new(), 0))
    ///     .get_result::<Vec<i32>>(connection)?;
    /// assert_eq!(Vec::<i32>::new(), trimmed_array);
    ///
    /// let trimmed_array = diesel::select(trim_array::<Nullable<Array<Integer>>, _, _>(None::<Vec<i32>>, 0))
    ///     .get_result::<Option<Vec<i32>>>(connection)?;
    /// assert_eq!(None, trimmed_array);
    ///
    /// let trimmed_array = diesel::select(trim_array::<Nullable<Array<Integer>>, _, _>(None::<Vec<i32>>, 1))
    ///     .get_result::<Option<Vec<i32>>>(connection)?;
    /// assert_eq!(None, trimmed_array);
    /// # Ok(())
    /// # }
    ///
    fn trim_array<Arr:ArrayOrNullableArray + SingleValue>(a: Arr, n: Integer) -> Arr;
}

#[cfg(feature = "postgres_backend")]
define_sql_function! {
    /// Concatenates two arrays
    ///
    /// # Example
    ///
    /// ```rust
    /// # include!("../../doctest_setup.rs");
    /// #
    /// # fn main() {
    /// #     run_test().unwrap();
    /// # }
    /// #
    /// # fn run_test() -> QueryResult<()> {
    /// #     use diesel::dsl::array_cat;
    /// #     use diesel::sql_types::{Integer, Array, Nullable};
    /// #     let connection = &mut establish_connection();
    /// let result = diesel::select(array_cat::<Array<Integer>, _, _>(vec![1, 2], vec![3, 4]))
    ///     .get_result::<Vec<i32>>(connection)?;
    /// assert_eq!(vec![1, 2, 3, 4], result);
    ///