From 153f02a8315559628aa58dad4b0fbd877d2b1b83 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Mon, 4 Dec 2023 11:00:33 +0100 Subject: [PATCH] feat(input): implement parsing from ws-separated string Signed-off-by: Matej Focko --- src/input.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/input.rs b/src/input.rs index a886a41..fbe8316 100644 --- a/src/input.rs +++ b/src/input.rs @@ -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(s: &str) -> B +where + B: FromIterator, + ::Err: Debug, +{ + s.split_ascii_whitespace() + .map(|n| n.parse().unwrap()) + .collect() +}