lodash_rs/
cast_array.rs

1
2/**
3Casts value as an array.
4If it is a n array already it will be nested.
5
6Example
7````
8use lodash_rs::cast_array;
9
10let res = cast_array(0);
11println!("{:?}", res); // [0]
12
13let res = cast_array([0]);
14println!("{:?}", res); // [[0]]
15*/
16pub fn cast_array<T>(value: T) -> Vec<T> {
17    vec![value]
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23
24    #[test]
25    fn works_with_strings() {
26        assert_eq!(cast_array("Word"), ["Word"]);
27    }
28
29    #[test]
30    fn works_with_numbers() {
31        assert_eq!(cast_array(0), [0]);
32    }
33}