change from BTreeMap to OrderMap

This commit is contained in:
Sam Rijs 2018-02-11 21:25:07 +11:00
parent 52e3fc4d28
commit c0d7d7e313
4 changed files with 17 additions and 19 deletions

View file

@ -11,7 +11,7 @@ hyper = "0.11.15"
hyper-tls = "0.1.2" hyper-tls = "0.1.2"
lazy_static = "1.0.0" lazy_static = "1.0.0"
maud = "0.17.2" maud = "0.17.2"
ordermap = "0.4.0" ordermap = { version = "0.4.0", features = ["serde-1"] }
relative-path = { version = "0.3.7", features = ["serde"] } relative-path = { version = "0.3.7", features = ["serde"] }
route-recognizer = "0.1.12" route-recognizer = "0.1.12"
semver = { version = "0.9.0", features = ["serde"] } semver = { version = "0.9.0", features = ["serde"] }

View file

@ -1,8 +1,8 @@
use std::borrow::Borrow; use std::borrow::Borrow;
use std::collections::BTreeMap;
use std::str::FromStr; use std::str::FromStr;
use failure::Error; use failure::Error;
use ordermap::OrderMap;
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use semver::{Version, VersionReq}; use semver::{Version, VersionReq};
@ -68,9 +68,9 @@ impl CrateDep {
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct CrateDeps { pub struct CrateDeps {
pub main: BTreeMap<CrateName, CrateDep>, pub main: OrderMap<CrateName, CrateDep>,
pub dev: BTreeMap<CrateName, CrateDep>, pub dev: OrderMap<CrateName, CrateDep>,
pub build: BTreeMap<CrateName, CrateDep> pub build: OrderMap<CrateName, CrateDep>
} }
#[derive(Debug)] #[derive(Debug)]
@ -96,9 +96,9 @@ impl AnalyzedDependency {
#[derive(Debug)] #[derive(Debug)]
pub struct AnalyzedDependencies { pub struct AnalyzedDependencies {
pub main: BTreeMap<CrateName, AnalyzedDependency>, pub main: OrderMap<CrateName, AnalyzedDependency>,
pub dev: BTreeMap<CrateName, AnalyzedDependency>, pub dev: OrderMap<CrateName, AnalyzedDependency>,
pub build: BTreeMap<CrateName, AnalyzedDependency> pub build: OrderMap<CrateName, AnalyzedDependency>
} }
impl AnalyzedDependencies { impl AnalyzedDependencies {

View file

@ -1,6 +1,5 @@
use std::collections::BTreeMap;
use failure::Error; use failure::Error;
use ordermap::OrderMap;
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use semver::VersionReq; use semver::VersionReq;
use toml; use toml;
@ -38,13 +37,13 @@ struct CargoToml {
#[serde(default)] #[serde(default)]
workspace: Option<CargoTomlWorkspace>, workspace: Option<CargoTomlWorkspace>,
#[serde(default)] #[serde(default)]
dependencies: BTreeMap<String, CargoTomlDependency>, dependencies: OrderMap<String, CargoTomlDependency>,
#[serde(rename = "dev-dependencies")] #[serde(rename = "dev-dependencies")]
#[serde(default)] #[serde(default)]
dev_dependencies: BTreeMap<String, CargoTomlDependency>, dev_dependencies: OrderMap<String, CargoTomlDependency>,
#[serde(rename = "build-dependencies")] #[serde(rename = "build-dependencies")]
#[serde(default)] #[serde(default)]
build_dependencies: BTreeMap<String, CargoTomlDependency> build_dependencies: OrderMap<String, CargoTomlDependency>
} }
fn convert_dependency(cargo_dep: (String, CargoTomlDependency)) -> Option<Result<(CrateName, CrateDep), Error>> { fn convert_dependency(cargo_dep: (String, CargoTomlDependency)) -> Option<Result<(CrateName, CrateDep), Error>> {
@ -86,11 +85,11 @@ pub fn parse_manifest_toml(input: &str) -> Result<CrateManifest, Error> {
let crate_name = package.name.parse::<CrateName>()?; let crate_name = package.name.parse::<CrateName>()?;
let dependencies = cargo_toml.dependencies let dependencies = cargo_toml.dependencies
.into_iter().filter_map(convert_dependency).collect::<Result<BTreeMap<_, _>, _>>()?; .into_iter().filter_map(convert_dependency).collect::<Result<OrderMap<_, _>, _>>()?;
let dev_dependencies = cargo_toml.dev_dependencies let dev_dependencies = cargo_toml.dev_dependencies
.into_iter().filter_map(convert_dependency).collect::<Result<BTreeMap<_, _>, _>>()?; .into_iter().filter_map(convert_dependency).collect::<Result<OrderMap<_, _>, _>>()?;
let build_dependencies = cargo_toml.build_dependencies let build_dependencies = cargo_toml.build_dependencies
.into_iter().filter_map(convert_dependency).collect::<Result<BTreeMap<_, _>, _>>()?; .into_iter().filter_map(convert_dependency).collect::<Result<OrderMap<_, _>, _>>()?;
let deps = CrateDeps { let deps = CrateDeps {
main: dependencies, main: dependencies,

View file

@ -1,8 +1,7 @@
use std::collections::BTreeMap;
use base64::display::Base64Display; use base64::display::Base64Display;
use hyper::Response; use hyper::Response;
use maud::{Markup, html}; use maud::{Markup, html};
use ordermap::OrderMap;
use ::engine::AnalyzeDependenciesOutcome; use ::engine::AnalyzeDependenciesOutcome;
use ::models::crates::{CrateName, AnalyzedDependency, AnalyzedDependencies}; use ::models::crates::{CrateName, AnalyzedDependency, AnalyzedDependencies};
@ -34,7 +33,7 @@ fn dependency_tables(crate_name: CrateName, deps: AnalyzedDependencies) -> Marku
} }
} }
fn dependency_table(title: &str, deps: BTreeMap<CrateName, AnalyzedDependency>) -> Markup { fn dependency_table(title: &str, deps: OrderMap<CrateName, AnalyzedDependency>) -> Markup {
let count_total = deps.len(); let count_total = deps.len();
let count_outdated = deps.iter().filter(|&(_, dep)| dep.is_outdated()).count(); let count_outdated = deps.iter().filter(|&(_, dep)| dep.is_outdated()).count();