feat(input): add ‹parse_separated›
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
9abfb4d18d
commit
501d8cb515
1 changed files with 10 additions and 0 deletions
10
src/input.rs
10
src/input.rs
|
@ -75,3 +75,13 @@ where
|
|||
.map(|n| n.parse().unwrap())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Parses a string of separated elements with given character and returns them
|
||||
/// as a collection.
|
||||
pub fn parse_separated<B, T: FromStr>(c: char, s: &str) -> B
|
||||
where
|
||||
B: FromIterator<T>,
|
||||
<T as FromStr>::Err: Debug,
|
||||
{
|
||||
s.split(c).map(|n| n.parse().unwrap()).collect()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue