Skip to content

Commit 65780b2

Browse files
committed
Merge remote-tracking branch 'upstream/pr/801'
2 parents b2ee89c + 5ffc714 commit 65780b2

30 files changed

+678
-599
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ curl = "0.4"
3636
oauth2 = "0.3"
3737
log = "0.3"
3838
env_logger = "0.4"
39-
rustc-serialize = "0.3"
39+
hex = "0.2"
4040
license-exprs = "^1.3"
4141
dotenv = "0.10.0"
42-
toml = "0.2"
42+
toml = "0.4"
4343
diesel = { version = "0.13.0", features = ["postgres", "serde_json", "deprecated-time", "chrono"] }
4444
diesel_codegen = "0.13.0"
4545
r2d2-diesel = "0.13.0"

src/badge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum Badge {
4444
},
4545
}
4646

47-
#[derive(RustcEncodable, RustcDecodable, PartialEq, Debug, Deserialize)]
47+
#[derive(PartialEq, Debug, Serialize, Deserialize)]
4848
pub struct EncodableBadge {
4949
pub badge_type: String,
5050
pub attributes: HashMap<String, Option<String>>,

src/bin/fill-in-user-id.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
extern crate cargo_registry;
1111
extern crate git2;
1212
extern crate postgres;
13-
extern crate rustc_serialize;
13+
#[macro_use]
14+
extern crate serde_derive;
1415

1516
use std::path::PathBuf;
1617

@@ -44,7 +45,7 @@ fn main() {
4445
}
4546
}
4647

47-
#[derive(RustcDecodable)]
48+
#[derive(Deserialize)]
4849
struct GithubUser {
4950
login: String,
5051
id: i32,

src/categories.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Category {
3939
}
4040
}
4141

42-
fn required_string_from_toml<'a>(toml: &'a toml::Table, key: &str) -> CargoResult<&'a str> {
42+
fn required_string_from_toml<'a>(toml: &'a toml::value::Table, key: &str) -> CargoResult<&'a str> {
4343
toml.get(key).and_then(toml::Value::as_str).chain_error(|| {
4444
internal(&format_args!(
4545
"Expected category TOML attribute '{}' to be a String",
@@ -48,12 +48,12 @@ fn required_string_from_toml<'a>(toml: &'a toml::Table, key: &str) -> CargoResul
4848
})
4949
}
5050

51-
fn optional_string_from_toml<'a>(toml: &'a toml::Table, key: &str) -> &'a str {
51+
fn optional_string_from_toml<'a>(toml: &'a toml::value::Table, key: &str) -> &'a str {
5252
toml.get(key).and_then(toml::Value::as_str).unwrap_or("")
5353
}
5454

5555
fn categories_from_toml(
56-
categories: &toml::Table,
56+
categories: &toml::value::Table,
5757
parent: Option<&Category>,
5858
) -> CargoResult<Vec<Category>> {
5959
let mut result = vec![];
@@ -92,9 +92,8 @@ pub fn sync() -> CargoResult<()> {
9292
let tx = conn.transaction().unwrap();
9393

9494
let categories = include_str!("./categories.toml");
95-
let toml = toml::Parser::new(categories).parse().expect(
96-
"Could not parse categories.toml",
97-
);
95+
let toml: toml::value::Table =
96+
toml::from_str(categories).expect("Could not parse categories.toml");
9897

9998
let categories =
10099
categories_from_toml(&toml, None).expect("Could not convert categories from TOML");

src/category.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct CrateCategory {
3434
category_id: i32,
3535
}
3636

37-
#[derive(RustcEncodable, RustcDecodable, Debug)]
37+
#[derive(Serialize, Deserialize, Debug)]
3838
pub struct EncodableCategory {
3939
pub id: String,
4040
pub category: String,
@@ -44,7 +44,7 @@ pub struct EncodableCategory {
4444
pub crates_cnt: i32,
4545
}
4646

47-
#[derive(RustcEncodable, RustcDecodable, Debug)]
47+
#[derive(Serialize, Deserialize, Debug)]
4848
pub struct EncodableCategoryWithSubcategories {
4949
pub id: String,
5050
pub category: String,
@@ -261,12 +261,12 @@ pub fn index(req: &mut Request) -> CargoResult<Response> {
261261
// Query for the total count of categories
262262
let total = Category::count_toplevel(&conn)?;
263263

264-
#[derive(RustcEncodable)]
264+
#[derive(Serialize)]
265265
struct R {
266266
categories: Vec<EncodableCategory>,
267267
meta: Meta,
268268
}
269-
#[derive(RustcEncodable)]
269+
#[derive(Serialize)]
270270
struct Meta {
271271
total: i64,
272272
}
@@ -300,7 +300,7 @@ pub fn show(req: &mut Request) -> CargoResult<Response> {
300300
subcategories: subcats,
301301
};
302302

303-
#[derive(RustcEncodable)]
303+
#[derive(Serialize)]
304304
struct R {
305305
category: EncodableCategoryWithSubcategories,
306306
}
@@ -316,7 +316,7 @@ pub fn slugs(req: &mut Request) -> CargoResult<Response> {
316316
)?;
317317
let rows = stmt.query(&[])?;
318318

319-
#[derive(RustcEncodable)]
319+
#[derive(Serialize)]
320320
struct Slug {
321321
id: String,
322322
slug: String,
@@ -332,7 +332,7 @@ pub fn slugs(req: &mut Request) -> CargoResult<Response> {
332332
})
333333
.collect();
334334

335-
#[derive(RustcEncodable)]
335+
#[derive(Serialize)]
336336
struct R {
337337
category_slugs: Vec<Slug>,
338338
}

src/dependency.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct ReverseDependency {
3434
crate_downloads: i32,
3535
}
3636

37-
#[derive(RustcEncodable, RustcDecodable, Debug)]
37+
#[derive(Serialize, Deserialize, Debug)]
3838
pub struct EncodableDependency {
3939
pub id: i32,
4040
pub version_id: i32,
@@ -48,7 +48,8 @@ pub struct EncodableDependency {
4848
pub downloads: i32,
4949
}
5050

51-
#[derive(Copy, Clone, Debug)]
51+
#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
52+
#[serde(rename_all = "lowercase")]
5253
#[repr(u32)]
5354
pub enum Kind {
5455
Normal = 0,

src/download.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct NewVersionDownload(
2626
i32
2727
);
2828

29-
#[derive(RustcEncodable, RustcDecodable, Debug)]
29+
#[derive(Serialize, Deserialize, Debug)]
3030
pub struct EncodableVersionDownload {
3131
pub id: i32,
3232
pub version: i32,

src/git.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use std::path::{Path, PathBuf};
66

77
use semver;
88
use git2;
9-
use rustc_serialize::json;
9+
use serde_json;
1010

1111
use app::App;
1212
use dependency::Kind;
1313
use util::{CargoResult, internal};
1414

15-
#[derive(RustcEncodable, RustcDecodable, Debug)]
15+
#[derive(Serialize, Deserialize, Debug)]
1616
pub struct Crate {
1717
pub name: String,
1818
pub vers: String,
@@ -22,7 +22,7 @@ pub struct Crate {
2222
pub yanked: Option<bool>,
2323
}
2424

25-
#[derive(RustcEncodable, RustcDecodable, Debug)]
25+
#[derive(Serialize, Deserialize, Debug)]
2626
pub struct Dependency {
2727
pub name: String,
2828
pub req: String,
@@ -60,7 +60,7 @@ pub fn add_crate(app: &App, krate: &Crate) -> CargoResult<()> {
6060
|mut f| f.read_to_string(&mut prev),
6161
)?;
6262
}
63-
let s = json::encode(krate).unwrap();
63+
let s = serde_json::to_string(krate).unwrap();
6464
let new = prev + &s;
6565
let mut f = File::create(&dst)?;
6666
f.write_all(new.as_bytes())?;
@@ -85,14 +85,14 @@ pub fn yank(app: &App, krate: &str, version: &semver::Version, yanked: bool) ->
8585
)?;
8686
let new = prev.lines()
8787
.map(|line| {
88-
let mut git_crate = json::decode::<Crate>(line).map_err(|_| {
88+
let mut git_crate = serde_json::from_str::<Crate>(line).map_err(|_| {
8989
internal(&format_args!("couldn't decode: `{}`", line))
9090
})?;
9191
if git_crate.name != krate || git_crate.vers != version.to_string() {
9292
return Ok(line.to_string());
9393
}
9494
git_crate.yanked = Some(yanked);
95-
Ok(json::encode(&git_crate).unwrap())
95+
Ok(serde_json::to_string(&git_crate).unwrap())
9696
})
9797
.collect::<CargoResult<Vec<String>>>();
9898
let new = new?.join("\n");

src/http.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use curl::easy::{Easy, List};
33
use oauth2::*;
44
use app::App;
55
use util::{CargoResult, internal, ChainError, human};
6-
use rustc_serialize::{json, Decodable};
6+
use serde_json;
7+
use serde::Deserialize;
78
use std::str;
89

910

@@ -43,7 +44,10 @@ pub fn github(app: &App, url: &str, auth: &Token) -> Result<(Easy, Vec<u8>), cur
4344
}
4445

4546
/// Checks for normal responses
46-
pub fn parse_github_response<T: Decodable>(mut resp: Easy, data: &[u8]) -> CargoResult<T> {
47+
pub fn parse_github_response<'de, 'a: 'de, T: Deserialize<'de>>(
48+
mut resp: Easy,
49+
data: &'a [u8],
50+
) -> CargoResult<T> {
4751
match resp.response_code().unwrap() {
4852
200 => {} // Ok!
4953
403 => {
@@ -72,7 +76,7 @@ pub fn parse_github_response<T: Decodable>(mut resp: Easy, data: &[u8]) -> Cargo
7276
internal("github didn't send a utf8-response")
7377
})?;
7478

75-
json::decode(json).chain_error(|| internal("github didn't send a valid json response"))
79+
serde_json::from_str(json).chain_error(|| internal("github didn't send a valid json response"))
7680
}
7781

7882
/// Gets a token with the given string as the access token, but all

0 commit comments

Comments
 (0)