Skip to content

Commit

Permalink
index: Use ordered map for features
Browse files Browse the repository at this point in the history
  • Loading branch information
arlosi authored and Turbo87 committed Aug 19, 2022
1 parent 40710a2 commit a26e319
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cargo-registry-index/lib.rs
Expand Up @@ -5,7 +5,7 @@ extern crate serde;
pub mod testing;

use anyhow::{anyhow, Context};
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -101,7 +101,7 @@ pub struct Crate {
pub vers: String,
pub deps: Vec<Dependency>,
pub cksum: String,
pub features: HashMap<String, Vec<String>>,
pub features: BTreeMap<String, Vec<String>>,
/// This field contains features with new, extended syntax. Specifically,
/// namespaced features (`dep:`) and weak dependencies (`pkg?/feat`).
///
Expand All @@ -112,7 +112,7 @@ pub struct Crate {
/// will fail to load due to not being able to parse the new syntax, even
/// with a `Cargo.lock` file.
#[serde(skip_serializing_if = "Option::is_none")]
pub features2: Option<HashMap<String, Vec<String>>>,
pub features2: Option<BTreeMap<String, Vec<String>>>,
pub yanked: Option<bool>,
#[serde(default)]
pub links: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/krate/publish.rs
Expand Up @@ -3,7 +3,7 @@
use flate2::read::GzDecoder;
use hex::ToHex;
use sha2::{Digest, Sha256};
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::io::Read;
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -216,7 +216,7 @@ pub fn publish(req: &mut dyn RequestExt) -> EndpointResult {
.uploader()
.upload_crate(app.http_client(), tarball, &krate, vers)?;

let (features, features2): (HashMap<_, _>, HashMap<_, _>) =
let (features, features2): (BTreeMap<_, _>, BTreeMap<_, _>) =
features.into_iter().partition(|(_k, vals)| {
!vals
.iter()
Expand Down
6 changes: 3 additions & 3 deletions src/tests/krate/publish.rs
Expand Up @@ -11,7 +11,7 @@ use diesel::{delete, update, ExpressionMethods, QueryDsl, RunQueryDsl};
use flate2::write::GzEncoder;
use flate2::Compression;
use http::StatusCode;
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::io::Read;
use std::iter::FromIterator;
use std::time::Duration;
Expand Down Expand Up @@ -953,9 +953,9 @@ fn features_version_2() {
assert_eq!(crates[0].name, "foo");
assert_eq!(crates[0].deps.len(), 1);
assert_eq!(crates[0].v, Some(2));
let features = HashMap::from_iter([("old_feat".to_string(), vec![])]);
let features = BTreeMap::from_iter([("old_feat".to_string(), vec![])]);
assert_eq!(crates[0].features, features);
let features2 = HashMap::from_iter([(
let features2 = BTreeMap::from_iter([(
"new_feat".to_string(),
vec!["dep:bar".to_string(), "bar?/feat".to_string()],
)]);
Expand Down

0 comments on commit a26e319

Please sign in to comment.