I want to convert an array of [Decimal; 12]
into [String; 12]
I use decimal module to store numbers, but I need to convert it into string for display
fn rows_to_string(arr: [Decimal; 12]) -> [String; 12] {
arr.into_iter().map(|row| row.to_string()).collect()
}
But this give me error:
error: an array of type `[std::string::String; 12]` cannot be built directly from an iterator
label: try collecting into a `Vec<std::string::String>`, then using `.try_into()`
note: required by a bound in `collect`
label: try collecting into a `Vec<std::string::String>`, then using `.try_into()`
if I follow the error instruction and change the code above into:
fn rows_to_string(arr: [Decimal; 12]) -> [String; 12] {
arr.into_iter()
.map(|row| row.to_string())
.collect::<Vec<String>>()
}
Now, the function returns a vector Vec<String>
, instead of [String; 12]