generated from janezicmatej/aoc-template
feat: prepare basic parsers
This commit is contained in:
@@ -1 +1,4 @@
|
||||
#![feature(pattern)]
|
||||
|
||||
pub mod parsers;
|
||||
pub mod template;
|
||||
|
20
src/parsers.rs
Normal file
20
src/parsers.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use std::str::{pattern::Pattern, FromStr};
|
||||
|
||||
pub fn to_vec<'a, T, P>(s: &'a str, pat: P) -> Vec<T>
|
||||
where
|
||||
T: FromStr,
|
||||
P: Pattern<'a>,
|
||||
{
|
||||
s.split(pat).filter_map(|x| x.parse().ok()).collect()
|
||||
}
|
||||
|
||||
pub fn to_vec_map<'a, T, U, P>(s: &'a str, pat: P, func: impl FnMut(T) -> U) -> Vec<U>
|
||||
where
|
||||
T: FromStr,
|
||||
P: Pattern<'a>,
|
||||
{
|
||||
s.split(pat)
|
||||
.filter_map(|x| x.parse().ok())
|
||||
.map(func)
|
||||
.collect()
|
||||
}
|
Reference in New Issue
Block a user