Skip to content

Drop rustc-serialize dependency #801

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 3 commits into from
Jul 8, 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
639 changes: 394 additions & 245 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ curl = "0.4"
oauth2 = "0.3"
log = "0.3"
env_logger = "0.4"
rustc-serialize = "0.3"
hex = "0.2"
license-exprs = "^1.3"
dotenv = "0.10.0"
toml = "0.2"
toml = "0.4"
diesel = { version = "0.13.0", features = ["postgres", "serde_json", "deprecated-time", "chrono"] }
diesel_codegen = "0.13.0"
r2d2-diesel = "0.13.0"
Expand Down
2 changes: 1 addition & 1 deletion src/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum Badge {
},
}

#[derive(RustcEncodable, RustcDecodable, PartialEq, Debug, Deserialize)]
#[derive(PartialEq, Debug, Serialize, Deserialize)]
pub struct EncodableBadge {
pub badge_type: String,
pub attributes: HashMap<String, Option<String>>,
Expand Down
5 changes: 3 additions & 2 deletions src/bin/fill-in-user-id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
extern crate cargo_registry;
extern crate git2;
extern crate postgres;
extern crate rustc_serialize;
#[macro_use]
extern crate serde_derive;

use std::path::PathBuf;

Expand Down Expand Up @@ -44,7 +45,7 @@ fn main() {
}
}

#[derive(RustcDecodable)]
#[derive(Deserialize)]
struct GithubUser {
login: String,
id: i32,
Expand Down
11 changes: 5 additions & 6 deletions src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Category {
}
}

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

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

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

let categories = include_str!("./categories.toml");
let toml = toml::Parser::new(categories).parse().expect(
"Could not parse categories.toml",
);
let toml: toml::value::Table =
toml::from_str(categories).expect("Could not parse categories.toml");

let categories =
categories_from_toml(&toml, None).expect("Could not convert categories from TOML");
Expand Down
14 changes: 7 additions & 7 deletions src/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct CrateCategory {
category_id: i32,
}

#[derive(RustcEncodable, RustcDecodable, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct EncodableCategory {
pub id: String,
pub category: String,
Expand All @@ -45,7 +45,7 @@ pub struct EncodableCategory {
pub crates_cnt: i32,
}

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

#[derive(RustcEncodable)]
#[derive(Serialize)]
struct R {
categories: Vec<EncodableCategory>,
meta: Meta,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct Meta {
total: i64,
}
Expand Down Expand Up @@ -379,7 +379,7 @@ pub fn show(req: &mut Request) -> CargoResult<Response> {
subcategories: subcats,
};

#[derive(RustcEncodable)]
#[derive(Serialize)]
struct R {
category: EncodableCategoryWithSubcategories,
}
Expand All @@ -395,7 +395,7 @@ pub fn slugs(req: &mut Request) -> CargoResult<Response> {
)?;
let rows = stmt.query(&[])?;

#[derive(RustcEncodable)]
#[derive(Serialize)]
struct Slug {
id: String,
slug: String,
Expand All @@ -411,7 +411,7 @@ pub fn slugs(req: &mut Request) -> CargoResult<Response> {
})
.collect();

#[derive(RustcEncodable)]
#[derive(Serialize)]
struct R {
category_slugs: Vec<Slug>,
}
Expand Down
5 changes: 3 additions & 2 deletions src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct ReverseDependency {
crate_downloads: i32,
}

#[derive(RustcEncodable, RustcDecodable, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct EncodableDependency {
pub id: i32,
pub version_id: i32,
Expand All @@ -48,7 +48,8 @@ pub struct EncodableDependency {
pub downloads: i32,
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
#[serde(rename_all = "lowercase")]
#[repr(u32)]
pub enum Kind {
Normal = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct NewVersionDownload(
i32
);

#[derive(RustcEncodable, RustcDecodable, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct EncodableVersionDownload {
pub id: i32,
pub version: i32,
Expand Down
12 changes: 6 additions & 6 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::path::{Path, PathBuf};

use semver;
use git2;
use rustc_serialize::json;
use serde_json;

use app::App;
use dependency::Kind;
use util::{CargoResult, internal};

#[derive(RustcEncodable, RustcDecodable, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct Crate {
pub name: String,
pub vers: String,
Expand All @@ -22,7 +22,7 @@ pub struct Crate {
pub yanked: Option<bool>,
}

#[derive(RustcEncodable, RustcDecodable, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct Dependency {
pub name: String,
pub req: String,
Expand Down Expand Up @@ -60,7 +60,7 @@ pub fn add_crate(app: &App, krate: &Crate) -> CargoResult<()> {
|mut f| f.read_to_string(&mut prev),
)?;
}
let s = json::encode(krate).unwrap();
let s = serde_json::to_string(krate).unwrap();
let new = prev + &s;
let mut f = File::create(&dst)?;
f.write_all(new.as_bytes())?;
Expand All @@ -85,14 +85,14 @@ pub fn yank(app: &App, krate: &str, version: &semver::Version, yanked: bool) ->
)?;
let new = prev.lines()
.map(|line| {
let mut git_crate = json::decode::<Crate>(line).map_err(|_| {
let mut git_crate = serde_json::from_str::<Crate>(line).map_err(|_| {
internal(&format_args!("couldn't decode: `{}`", line))
})?;
if git_crate.name != krate || git_crate.vers != version.to_string() {
return Ok(line.to_string());
}
git_crate.yanked = Some(yanked);
Ok(json::encode(&git_crate).unwrap())
Ok(serde_json::to_string(&git_crate).unwrap())
})
.collect::<CargoResult<Vec<String>>>();
let new = new?.join("\n");
Expand Down
10 changes: 7 additions & 3 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use curl::easy::{Easy, List};
use oauth2::*;
use app::App;
use util::{CargoResult, internal, ChainError, human};
use rustc_serialize::{json, Decodable};
use serde_json;
use serde::Deserialize;
use std::str;


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

/// Checks for normal responses
pub fn parse_github_response<T: Decodable>(mut resp: Easy, data: &[u8]) -> CargoResult<T> {
pub fn parse_github_response<'de, 'a: 'de, T: Deserialize<'de>>(
mut resp: Easy,
data: &'a [u8],
) -> CargoResult<T> {
match resp.response_code().unwrap() {
200 => {} // Ok!
403 => {
Expand Down Expand Up @@ -72,7 +76,7 @@ pub fn parse_github_response<T: Decodable>(mut resp: Easy, data: &[u8]) -> Cargo
internal("github didn't send a utf8-response")
})?;

json::decode(json).chain_error(|| internal("github didn't send a valid json response"))
serde_json::from_str(json).chain_error(|| internal("github didn't send a valid json response"))
}

/// Gets a token with the given string as the access token, but all
Expand Down
8 changes: 4 additions & 4 deletions src/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct CrateKeyword {
keyword_id: i32,
}

#[derive(RustcEncodable, RustcDecodable, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct EncodableKeyword {
pub id: String,
pub keyword: String,
Expand Down Expand Up @@ -165,12 +165,12 @@ pub fn index(req: &mut Request) -> CargoResult<Response> {
.map(|(k, _)| k.encodable())
.collect::<Vec<_>>();

#[derive(RustcEncodable)]
#[derive(Serialize)]
struct R {
keywords: Vec<EncodableKeyword>,
meta: Meta,
}
#[derive(RustcEncodable)]
#[derive(Serialize)]
struct Meta {
total: i64,
}
Expand All @@ -188,7 +188,7 @@ pub fn show(req: &mut Request) -> CargoResult<Response> {

let kw = Keyword::find_by_keyword(&conn, name)?;

#[derive(RustcEncodable)]
#[derive(Serialize)]
struct R {
keyword: EncodableKeyword,
}
Expand Down
Loading