From 19f97f917e79147eebd86739dea43c8df8bfd385 Mon Sep 17 00:00:00 2001 From: Sam Rijs Date: Sun, 11 Feb 2018 16:17:12 +1100 Subject: [PATCH] use OrderMap for crates list --- Cargo.toml | 1 + src/engine/machines/crawler.rs | 11 ++++++----- src/main.rs | 1 + src/models/crates.rs | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 25f9445..d804dbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ hyper = "0.11.15" hyper-tls = "0.1.2" lazy_static = "1.0.0" maud = "0.17.2" +ordermap = "0.4.0" route-recognizer = "0.1.12" semver = { version = "0.9.0", features = ["serde"] } serde = "1.0.27" diff --git a/src/engine/machines/crawler.rs b/src/engine/machines/crawler.rs index 1f9492e..9a4b875 100644 --- a/src/engine/machines/crawler.rs +++ b/src/engine/machines/crawler.rs @@ -2,12 +2,13 @@ use std::collections::HashMap; use std::path::PathBuf; use failure::Error; +use ordermap::map::OrderMap; use ::parsers::manifest::parse_manifest_toml; use ::models::crates::{CrateDeps, CrateName, CrateManifest}; pub struct ManifestCrawlerOutput { - pub crates: Vec<(CrateName, CrateDeps)> + pub crates: OrderMap } pub struct ManifestCrawlerStepOutput { @@ -16,14 +17,14 @@ pub struct ManifestCrawlerStepOutput { pub struct ManifestCrawler { manifests: HashMap, - leaf_crates: Vec<(CrateName, CrateDeps)> + leaf_crates: OrderMap } impl ManifestCrawler { pub fn new() -> ManifestCrawler { ManifestCrawler { manifests: HashMap::new(), - leaf_crates: vec![] + leaf_crates: OrderMap::new() } } @@ -37,7 +38,7 @@ impl ManifestCrawler { match manifest { CrateManifest::Package(name, deps) => { - self.leaf_crates.push((name, deps)); + self.leaf_crates.insert(name, deps); }, CrateManifest::Workspace { members } => { for mut member in members { @@ -45,7 +46,7 @@ impl ManifestCrawler { } }, CrateManifest::Mixed { name, deps, members } => { - self.leaf_crates.push((name, deps)); + self.leaf_crates.insert(name, deps); for mut member in members { output.paths_of_interest.push(path.clone().join(member)); } diff --git a/src/main.rs b/src/main.rs index 9436b32..4176812 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ extern crate hyper; extern crate hyper_tls; #[macro_use] extern crate lazy_static; extern crate maud; +extern crate ordermap; extern crate route_recognizer; extern crate semver; #[macro_use] extern crate serde_derive; diff --git a/src/models/crates.rs b/src/models/crates.rs index 78ef916..5f8827a 100644 --- a/src/models/crates.rs +++ b/src/models/crates.rs @@ -6,7 +6,7 @@ use std::str::FromStr; use failure::Error; use semver::{Version, VersionReq}; -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct CrateName(String); impl Into for CrateName {