diff --git a/src/lib.rs b/src/lib.rs index 612b5b9..d103939 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1 +1,4 @@ +#![feature(pattern)] + +pub mod parsers; pub mod template; diff --git a/src/parsers.rs b/src/parsers.rs new file mode 100644 index 000000000..a3f8d44 --- /dev/null +++ b/src/parsers.rs @@ -0,0 +1,20 @@ +use std::str::{pattern::Pattern, FromStr}; + +pub fn to_vec(s: &str, pat: P) -> Vec +where + T: FromStr, + P: Pattern, +{ + s.split(pat).filter_map(|x| x.parse().ok()).collect() +} + +pub fn to_vec_map(s: &str, pat: P, func: impl FnMut(T) -> U) -> Vec +where + T: FromStr, + P: Pattern, +{ + s.split(pat) + .filter_map(|x| x.parse().ok()) + .map(func) + .collect() +}