Skip to content

Revert serialization of features to string type #5292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2018
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
21 changes: 20 additions & 1 deletion src/cargo/core/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use std::mem;
use std::rc::Rc;

use semver::Version;

use serde::{Serialize, Serializer};

use core::{Dependency, PackageId, SourceId};
use core::interning::InternedString;

Expand Down Expand Up @@ -190,7 +193,7 @@ fn build_feature_map(
/// * A feature in a depedency
///
/// The selection between these 3 things happens as part of the construction of the FeatureValue.
#[derive(Clone, Debug, Serialize)]
#[derive(Clone, Debug)]
pub enum FeatureValue {
Feature(InternedString),
Crate(InternedString),
Expand Down Expand Up @@ -227,4 +230,20 @@ impl FeatureValue {
}
}

impl Serialize for FeatureValue {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
use self::FeatureValue::*;
match *self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorter, but less performance code is: serializer.serialize_str(*self.to_string()). But this works too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah -- it's only 7 low-complexity extra lines to avoid the allocations on the common path. I figured it was worth it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then this looks good to me. 👍

Feature(ref f) => serializer.serialize_str(f),
Crate(ref c) => serializer.serialize_str(c),
CrateFeature(ref c, ref f) => {
serializer.serialize_str(&[c.as_ref(), f.as_ref()].join("/"))
}
}
}
}

pub type FeatureMap = BTreeMap<String, Vec<FeatureValue>>;
4 changes: 1 addition & 3 deletions tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ optional_feat = []
],
"features": {
"default": [
{
"Feature": "default_feat"
}
"default_feat"
],
"default_feat": [],
"optional_feat": []
Expand Down