Skip to content

Commit

Permalink
Define the unavailable target just once and re-use it
Browse files Browse the repository at this point in the history
The same unavailable target value is used in two different places.
Abstracting it makes it easier to update it and recognise its purpose.
  • Loading branch information
ranma42 committed Apr 25, 2017
1 parent ac8892b commit 5439c9b
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/tools/build-manifest/src/main.rs
Expand Up @@ -120,6 +120,18 @@ struct Target {
extensions: Option<Vec<Component>>,
}

impl Target {
fn unavailable() -> Target {
Target {
available: false,
url: None,
hash: None,
components: None,
extensions: None,
}
}
}

#[derive(RustcEncodable)]
struct Component {
pkg: String,
Expand Down Expand Up @@ -242,13 +254,7 @@ impl Builder {
let digest = match self.digests.remove(&filename) {
Some(digest) => digest,
None => {
pkg.target.insert(host.to_string(), Target {
available: false,
url: None,
hash: None,
components: None,
extensions: None,
});
pkg.target.insert(host.to_string(), Target::unavailable());
continue
}
};
Expand Down Expand Up @@ -312,15 +318,7 @@ impl Builder {
let filename = self.filename(pkgname, name);
let digest = match self.digests.remove(&filename) {
Some(digest) => digest,
None => {
return (name.to_string(), Target {
available: false,
url: None,
hash: None,
components: None,
extensions: None,
})
}
None => return (name.to_string(), Target::unavailable()),
};

(name.to_string(), Target {
Expand Down

0 comments on commit 5439c9b

Please sign in to comment.