Skip to content

Commit

Permalink
metadata: factor out parse_deps_table()
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Desmottes authored and gdesmott committed Mar 16, 2021
1 parent 4dbe9e6 commit 9ac6f2f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,25 @@ impl MetaData {
.and_then(|v| v.get("system-deps"))
.ok_or_else(|| anyhow!("no {}", key))?;

let table = meta
let deps = Self::parse_deps_table(meta, key)?;

Ok(MetaData { deps })
}

fn parse_deps_table(table: &Value, key: &str) -> Result<Vec<Dependency>, Error> {
let table = table
.as_table()
.ok_or_else(|| anyhow!("{} not a table", key))?;

let mut deps = Vec::new();

for (name, value) in table {
let dep = Self::parse_dep(name, value)
.map_err(|e| anyhow!("metadata.system-deps.{}: {}", name, e))?;
let dep =
Self::parse_dep(name, value).map_err(|e| anyhow!("{}.{}: {}", key, name, e))?;
deps.push(dep);
}

Ok(MetaData { deps })
Ok(deps)
}

fn parse_dep(name: &str, value: &Value) -> Result<Dependency, Error> {
Expand Down

0 comments on commit 9ac6f2f

Please sign in to comment.