1
0
Fork 0

feat(input): implement parsing from ws-separated string

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-12-04 11:00:33 +01:00
parent 142dccf8f1
commit 153f02a831
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -63,3 +63,15 @@ where
.map(str::to_string)
.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()
}