feat: to_vec<T> and to_vec_vec<T> helpers

This commit is contained in:
Matej Janezic 2022-11-29 21:02:36 +01:00
parent 00000050ac
commit 0000006088
Signed by: janezicmatej
GPG Key ID: 4298E230ED37B2C0
1 changed files with 26 additions and 0 deletions

View File

@ -1 +1,27 @@
use std::{fmt::Debug, str::FromStr};
pub fn to_vec<T>(input: &str, split: char) -> Vec<T>
where
T: FromStr,
<T as FromStr>::Err: Debug,
{
input
.split(split)
.map(|x| x.parse::<T>().unwrap())
.collect()
}
pub fn to_vec_vec<T>(input: &str, split_rows: char, split_row: char) -> Vec<Vec<T>>
where
T: FromStr,
<T as FromStr>::Err: Debug,
{
input
.split(split_rows)
.map(|x| {
x.split(split_row)
.map(|y| y.parse::<T>().unwrap())
.collect()
})
.collect()
}