I have a value x
of the type Value
(from serde_json
).
I want to return Result<Option<String>, WrongFieldsError>
(WrongFieldsError
is my type).
- It is
Ok(None)
ifx
has no subobject with keysub
. - It is
Ok(Some(_))
ifx
has a string subobject with keysub
of string type. - It is
Err(WrongFieldsError)
ifx
has a string subobject with keysub
of non-string type.
How to write it in idiomatic Rust?
Isn't standard library (trait Option
) missing the version of map()
(or call it collect()
) that receives Option<Result<T, E>>
and returns Result<Option<T>, E>>
, similarly to "an iterator of Result<T, E>
items can be collected into Result<Collection<T>, E>
." for vectors?
Should we add something like this to the standard library, in order to ease solving problems like the problem above with serde_json
.