Given the array:
static STRS_UPPER: [&'static str; 3] = ["FOO", "BAR", "BAZ"];
What is a succinct way of passing a mapped representation (for example, making all strings lowercase) of the above array to a function with the signature:
fn print_str_slice(slice: &[&str]);
The above type parameters are fixed. I cannot change the signature of print_str_slice
or the type of STRS_UPPER
.
What I am doing currently:
let strings_lower = STRS_UPPER.iter()
.map(|s| s.to_string().to_ascii_lowercase())
.collect::<Vec<_>>();
print_str_slice(strings_lower.iter()
.map(AsRef::as_ref)
.collect::<Vec<_>>()
.as_slice()
);
Can this be done in a cleaner way, perhaps without the intermediary vector strings_lower
?