Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Define the unavailable target just once and re-use it
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
commit 5439c9b4ec975083cb1bc2000a5faa21f737997a
30 changes: 14 additions & 16 deletions src/tools/build-manifest/src/main.rs
Original file line number Diff line number Diff line change
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