Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/crates_io_index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ url = "=2.5.2"

[dev-dependencies]
claims = "=0.7.1"
insta = "=1.40.0"
6 changes: 3 additions & 3 deletions crates/crates_io_index/data.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::features::FeaturesMap;
use std::cmp::Ordering;
use std::collections::BTreeMap;

#[derive(Serialize, Deserialize, Debug)]
pub struct Crate {
pub name: String,
pub vers: String,
pub deps: Vec<Dependency>,
pub cksum: String,
pub features: BTreeMap<String, Vec<String>>,
pub features: FeaturesMap,
/// This field contains features with new, extended syntax. Specifically,
/// namespaced features (`dep:`) and weak dependencies (`pkg?/feat`).
///
Expand All @@ -18,7 +18,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<BTreeMap<String, Vec<String>>>,
pub features2: Option<FeaturesMap>,
pub yanked: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub links: Option<String>,
Expand Down
5 changes: 4 additions & 1 deletion src/models/feature.rs → crates/crates_io_index/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ pub type FeaturesMap = BTreeMap<String, Vec<String>>;
/// values.
///
/// See <https://rust-lang.github.io/rfcs/3143-cargo-weak-namespaced-features.html>.
pub fn split_features(features: FeaturesMap) -> (FeaturesMap, FeaturesMap) {
pub fn split_features(
features: impl IntoIterator<Item = (String, Vec<String>)>,
) -> (FeaturesMap, FeaturesMap) {
const ITERATION_LIMIT: usize = 100;

// First, we partition the features into two groups: those that use the new
Expand Down Expand Up @@ -49,6 +51,7 @@ pub fn split_features(features: FeaturesMap) -> (FeaturesMap, FeaturesMap) {
mod tests {
use super::*;
use insta::{assert_compact_debug_snapshot, assert_debug_snapshot};
use serde_json::json;

#[test]
fn test_split_features_no_deps() {
Expand Down
1 change: 1 addition & 0 deletions crates/crates_io_index/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate tracing;

mod credentials;
mod data;
pub mod features;
mod repo;
mod ser;
#[cfg(feature = "testing")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/models/feature.rs
source: crates/crates_io_index/features.rs
expression: split_features(features)
---
(
Expand Down
1 change: 0 additions & 1 deletion src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ mod default_versions;
pub mod dependency;
mod download;
mod email;
pub mod feature;
mod follow;
mod keyword;
pub mod krate;
Expand Down
2 changes: 1 addition & 1 deletion src/models/krate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use chrono::NaiveDateTime;
use crates_io_index::features::split_features;
use diesel::associations::Identifiable;
use diesel::dsl;
use diesel::pg::Pg;
Expand All @@ -8,7 +9,6 @@ use secrecy::SecretString;
use thiserror::Error;

use crate::controllers::helpers::pagination::*;
use crate::models::feature::split_features;
use crate::models::helpers::with_count::*;
use crate::models::version::TopVersions;
use crate::models::{
Expand Down
2 changes: 1 addition & 1 deletion src/models/version.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::collections::BTreeMap;

use chrono::NaiveDateTime;
use crates_io_index::features::FeaturesMap;
use derive_builder::Builder;
use diesel::prelude::*;
use serde::Deserialize;

use crate::util::errors::{bad_request, AppResult};

use crate::models::feature::FeaturesMap;
use crate::models::{Crate, Dependency, User};
use crate::schema::*;
use crate::sql::split_part;
Expand Down