simple_string_patterns/to_strings.rs
1
2
3/// Converts arrays or vectors of strs to a vector of owned strings
4pub trait ToStrings {
5 fn to_strings(&self) -> Vec<String>;
6}
7
8impl<T: ToString> ToStrings for Vec<T> {
9 /// Converts arrays or vectors of strs to a vector of owned strings
10 fn to_strings(&self) -> Vec<String> {
11 self.into_iter().map(|s| s.to_string()).collect()
12 }
13}
14
15impl<T: ToString> ToStrings for [T] {
16 /// Converts arrays or vectors of strs to a vector of owned strings
17 fn to_strings(&self) -> Vec<String> {
18 self.into_iter().map(|s| s.to_string()).collect::<Vec<String>>()
19 }
20}