MCPcopy Create free account
hub / github.com/archlinux/alpm / parse_optional_value

Function parse_optional_value

alpm-srcinfo/src/pkgbuild_bridge/mod.rs:155–169  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

153///
154/// Returns a error for `keyword` if `value` is not [`Value::Single`] or cannot be parsed as the
155/// specific type.
156fn 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.

Callers 2

handle_package_baseFunction · 0.85

Calls 3

ensure_single_valueFunction · 0.85
parseMethod · 0.80
is_emptyMethod · 0.45

Tested by 1