Ensures a combination of [`Keyword`] and [`Value`] uses a [`Value::Single`] and parses the value as a specific, but optional type. Returns [`None`] if `value` is **empty**. # Errors Returns a error for `keyword` if `value` is not [`Value::Single`] or cannot be parsed as the specific type.
(
keyword: &Keyword,
value: &'a Value,
mut parser: P,
)
| 153 | /// |
| 154 | /// Returns a error for `keyword` if `value` is not [`Value::Single`] or cannot be parsed as the |
| 155 | /// specific type. |
| 156 | fn parse_optional_value<'a, O, P: Parser<&'a str, O, ErrMode<ContextError>>>( |
| 157 | keyword: &Keyword, |
| 158 | value: &'a Value, |
| 159 | mut parser: P, |
| 160 | ) -> Result<Option<O>, BridgeError> { |
| 161 | let input = ensure_single_value(keyword, value)?; |
| 162 | |
| 163 | if input.trim().is_empty() { |
| 164 | return Ok(None); |
| 165 | } |
| 166 | |
| 167 | Ok(Some( |
| 168 | parser.parse(input).map_err(|err| (keyword.clone(), err))?, |
| 169 | )) |
| 170 | } |
| 171 | |
| 172 | /// Parses a [`Value`] as a [`Vec`] of specific types. |