From 00000060997615eeb9942f3771fc704190236e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Tue, 29 Nov 2022 21:02:36 +0100 Subject: [PATCH] feat: to_vec and to_vec_vec helpers --- src/helpers.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/helpers.rs b/src/helpers.rs index 8b13789..2c1df5c 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1 +1,27 @@ +use std::{fmt::Debug, str::FromStr}; +pub fn to_vec(input: &str, split: char) -> Vec +where + T: FromStr, + ::Err: Debug, +{ + input + .split(split) + .map(|x| x.parse::().unwrap()) + .collect() +} + +pub fn to_vec_vec(input: &str, split_rows: char, split_row: char) -> Vec> +where + T: FromStr, + ::Err: Debug, +{ + input + .split(split_rows) + .map(|x| { + x.split(split_row) + .map(|y| y.parse::().unwrap()) + .collect() + }) + .collect() +}