feat(input): implement parsing from ws-separated string
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
142dccf8f1
commit
153f02a831
1 changed files with 12 additions and 0 deletions
12
src/input.rs
12
src/input.rs
|
@ -63,3 +63,15 @@ where
|
||||||
.map(str::to_string)
|
.map(str::to_string)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parses a string of whitespace separated elements and returns them as
|
||||||
|
/// a collection.
|
||||||
|
pub fn parse_ws_separated<B, T: FromStr>(s: &str) -> B
|
||||||
|
where
|
||||||
|
B: FromIterator<T>,
|
||||||
|
<T as FromStr>::Err: Debug,
|
||||||
|
{
|
||||||
|
s.split_ascii_whitespace()
|
||||||
|
.map(|n| n.parse().unwrap())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue