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

Function parse_arch_array

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

Parses a [`Value`] as [`Architectures`]. # Errors Returns an error for `keyword` if `value` cannot be parsed as either a stand-alone "any" or a list of [`SystemArchitecture`].

(keyword: &Keyword, value: &'a Value)

Source from the content-addressed store, hash-verified

197///
198/// Returns an error for `keyword` if `value` cannot be parsed as either a stand-alone "any" or a
199/// list of [`SystemArchitecture`].
200fn parse_arch_array<'a>(keyword: &Keyword, value: &'a Value) -> Result<Architectures, BridgeError> {
201 // `arch` may be a list or a single value (for backward compatibility).
202 let input = value.as_vec();
203
204 // First check if the entry is a single "any".
205 // `arch = "any"`
206 // or
207 // `arch = ("any")`
208 if input.len() == 1 && input[0] == "any" {
209 return Ok(Architectures::Any);
210 }
211
212 let architectures = input
213 .into_iter()
214 .map(|item| {
215 SystemArchitecture::parser
216 .context(StrContext::Expected(StrContextValue::Description(
217 "either a single 'any' or an array of one or more specific system architectures."
218 )))
219 .parse(item)
220 .map_err(|err| (keyword.clone(), err))
221 })
222 .collect::<Result<Vec<SystemArchitecture>, (Keyword, ParseError<&'a str, ContextError>)>>()?;
223
224 Ok(Architectures::Some(architectures))
225}
226
227#[cfg(test)]

Callers 1

handle_package_baseFunction · 0.85

Calls 4

as_vecMethod · 0.80
parseMethod · 0.80
lenMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected