Ergonomic way to combine parsers of different types? #621
Answered
by
epage
npetrangelo
asked this question in
Q&A
-
I want to do something like this, but the Map type seems to have too much type information to map everything to the same type for pub fn parse_value(s: &mut &str) -> PResult<Value> {
alt([
parse_string.map(|s| Value::String(s)),
parse_float.map(|f| Value::Float(f)),
parse_int.map(|i| Value::Int(i)),
parse_bool.map(|b| Value::Bool(b)),
parse_range.map(|r| Value::Range(r))])
.parse_next(s)
} |
Beta Was this translation helpful? Give feedback.
Answered by
epage
Nov 15, 2024
Replies: 1 comment
-
Instead of |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
npetrangelo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of
[]
in thealt
, use()
which allows different types. Thats the primary way we recommend people usealt
. ‘[]` support is newer and more for some corner cases.