Skip to content
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

Migrate from rustc-serialize to Serde #3682

Merged
merged 1 commit into from
Feb 22, 2017
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
101 changes: 98 additions & 3 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ log = "0.3"
num_cpus = "1.0"
rustc-serialize = "0.3"
semver = "0.6.0"
serde = "0.9"
serde_derive = "0.9"
serde_json = "0.9"
serde_ignored = "0.0.2"
shell-escape = "0.1"
tar = { version = "0.4", default-features = false }
tempdir = "0.3"
term = "0.4.4"
toml = "0.2"
toml = "0.3"
url = "1.1"

[target.'cfg(unix)'.dependencies]
Expand Down
3 changes: 3 additions & 0 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ extern crate rustc_serialize;
extern crate toml;
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;

use std::collections::BTreeSet;
use std::collections::HashMap;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/locate_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Options:
-h, --help Print this message
";

#[derive(RustcEncodable)]
#[derive(Serialize)]
pub struct ProjectLocation {
root: String
}
Expand Down
11 changes: 5 additions & 6 deletions src/bin/verify_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::process;
use cargo;
use cargo::util::important_paths::{find_root_manifest_for_wd};
use cargo::util::{CliResult, Config};
use rustc_serialize::json;
use serde_json;
use toml;

#[derive(RustcDecodable)]
Expand Down Expand Up @@ -55,10 +55,9 @@ pub fn execute(args: Flags, config: &Config) -> CliResult {
Ok(_) => {},
Err(e) => fail("invalid", &format!("error reading file: {}", e))
};
match toml::Parser::new(&contents).parse() {
None => fail("invalid", "invalid-format"),
Some(..) => {}
};
if contents.parse::<toml::Value>().is_err() {
fail("invalid", "invalid-format");
}

let mut h = HashMap::new();
h.insert("success".to_string(), "true".to_string());
Expand All @@ -69,6 +68,6 @@ pub fn execute(args: Flags, config: &Config) -> CliResult {
fn fail(reason: &str, value: &str) -> ! {
let mut h = HashMap::new();
h.insert(reason.to_string(), value.to_string());
println!("{}", json::encode(&h).unwrap());
println!("{}", serde_json::to_string(&h).unwrap());
process::exit(1)
}
30 changes: 18 additions & 12 deletions src/cargo/core/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::str::FromStr;

use semver::VersionReq;
use semver::ReqParseError;
use rustc_serialize::{Encoder, Encodable};
use serde::ser;

use core::{SourceId, Summary, PackageId};
use util::{CargoError, CargoResult, Cfg, CfgExpr, ChainError, human, Config};
Expand Down Expand Up @@ -41,7 +41,7 @@ pub enum Platform {
Cfg(CfgExpr),
}

#[derive(RustcEncodable)]
#[derive(Serialize)]
struct SerializedDependency<'a> {
name: &'a str,
source: &'a SourceId,
Expand All @@ -54,8 +54,10 @@ struct SerializedDependency<'a> {
target: Option<&'a Platform>,
}

impl Encodable for Dependency {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
impl ser::Serialize for Dependency {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where S: ser::Serializer,
{
SerializedDependency {
name: self.name(),
source: &self.source_id(),
Expand All @@ -65,7 +67,7 @@ impl Encodable for Dependency {
uses_default_features: self.uses_default_features(),
features: self.features(),
target: self.platform(),
}.encode(s)
}.serialize(s)
}
}

Expand All @@ -76,13 +78,15 @@ pub enum Kind {
Build,
}

impl Encodable for Kind {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
impl ser::Serialize for Kind {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where S: ser::Serializer,
{
match *self {
Kind::Normal => None,
Kind::Development => Some("dev"),
Kind::Build => Some("build"),
}.encode(s)
}.serialize(s)
}
}

Expand Down Expand Up @@ -136,7 +140,7 @@ This will soon become a hard error, so it's either recommended to
update to a fixed version or contact the upstream maintainer about
this warning.
",
req, inside.name(), inside.version(), requirement);
req, inside.name(), inside.version(), requirement);
config.shell().warn(&msg)?;

Ok(requirement)
Expand Down Expand Up @@ -348,9 +352,11 @@ impl Platform {
}
}

impl Encodable for Platform {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
self.to_string().encode(s)
impl ser::Serialize for Platform {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where S: ser::Serializer,
{
self.to_string().serialize(s)
}
}

Expand Down
Loading