Skip to content

Commit be0b499

Browse files
committed
Auto merge of #3682 - alexcrichton:serde, r=brson
Migrate from rustc-serialize to Serde This commit migrates Cargo as much as possible from rustc-serialize to Serde. This not only provides an excellent testing ground for the toml 0.3 release but it also is a big boost to the speed of parsing the JSON bits of the registry. This doesn't completely excise the dependency just yet as docopt still requires it along with handlebars. I'm sure though that in time those crates will migrate to serde!
2 parents e278ea3 + a5a298f commit be0b499

35 files changed

+673
-564
lines changed

Cargo.lock

Lines changed: 98 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ log = "0.3"
3535
num_cpus = "1.0"
3636
rustc-serialize = "0.3"
3737
semver = "0.6.0"
38+
serde = "0.9"
39+
serde_derive = "0.9"
40+
serde_json = "0.9"
41+
serde_ignored = "0.0.2"
3842
shell-escape = "0.1"
3943
tar = { version = "0.4", default-features = false }
4044
tempdir = "0.3"
4145
term = "0.4.4"
42-
toml = "0.2"
46+
toml = "0.3"
4347
url = "1.1"
4448

4549
[target.'cfg(unix)'.dependencies]

src/bin/cargo.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ extern crate rustc_serialize;
66
extern crate toml;
77
#[macro_use]
88
extern crate log;
9+
#[macro_use]
10+
extern crate serde_derive;
11+
extern crate serde_json;
912

1013
use std::collections::BTreeSet;
1114
use std::collections::HashMap;

src/bin/locate_project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Options:
1818
-h, --help Print this message
1919
";
2020

21-
#[derive(RustcEncodable)]
21+
#[derive(Serialize)]
2222
pub struct ProjectLocation {
2323
root: String
2424
}

src/bin/verify_project.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::process;
66
use cargo;
77
use cargo::util::important_paths::{find_root_manifest_for_wd};
88
use cargo::util::{CliResult, Config};
9-
use rustc_serialize::json;
9+
use serde_json;
1010
use toml;
1111

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

6362
let mut h = HashMap::new();
6463
h.insert("success".to_string(), "true".to_string());
@@ -69,6 +68,6 @@ pub fn execute(args: Flags, config: &Config) -> CliResult {
6968
fn fail(reason: &str, value: &str) -> ! {
7069
let mut h = HashMap::new();
7170
h.insert(reason.to_string(), value.to_string());
72-
println!("{}", json::encode(&h).unwrap());
71+
println!("{}", serde_json::to_string(&h).unwrap());
7372
process::exit(1)
7473
}

src/cargo/core/dependency.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::str::FromStr;
44

55
use semver::VersionReq;
66
use semver::ReqParseError;
7-
use rustc_serialize::{Encoder, Encodable};
7+
use serde::ser;
88

99
use core::{SourceId, Summary, PackageId};
1010
use util::{CargoError, CargoResult, Cfg, CfgExpr, ChainError, human, Config};
@@ -41,7 +41,7 @@ pub enum Platform {
4141
Cfg(CfgExpr),
4242
}
4343

44-
#[derive(RustcEncodable)]
44+
#[derive(Serialize)]
4545
struct SerializedDependency<'a> {
4646
name: &'a str,
4747
source: &'a SourceId,
@@ -54,8 +54,10 @@ struct SerializedDependency<'a> {
5454
target: Option<&'a Platform>,
5555
}
5656

57-
impl Encodable for Dependency {
58-
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
57+
impl ser::Serialize for Dependency {
58+
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
59+
where S: ser::Serializer,
60+
{
5961
SerializedDependency {
6062
name: self.name(),
6163
source: &self.source_id(),
@@ -65,7 +67,7 @@ impl Encodable for Dependency {
6567
uses_default_features: self.uses_default_features(),
6668
features: self.features(),
6769
target: self.platform(),
68-
}.encode(s)
70+
}.serialize(s)
6971
}
7072
}
7173

@@ -76,13 +78,15 @@ pub enum Kind {
7678
Build,
7779
}
7880

79-
impl Encodable for Kind {
80-
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
81+
impl ser::Serialize for Kind {
82+
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
83+
where S: ser::Serializer,
84+
{
8185
match *self {
8286
Kind::Normal => None,
8387
Kind::Development => Some("dev"),
8488
Kind::Build => Some("build"),
85-
}.encode(s)
89+
}.serialize(s)
8690
}
8791
}
8892

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

142146
Ok(requirement)
@@ -348,9 +352,11 @@ impl Platform {
348352
}
349353
}
350354

351-
impl Encodable for Platform {
352-
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
353-
self.to_string().encode(s)
355+
impl ser::Serialize for Platform {
356+
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
357+
where S: ser::Serializer,
358+
{
359+
self.to_string().serialize(s)
354360
}
355361
}
356362

0 commit comments

Comments
 (0)