Skip to content

Commit

Permalink
feat(lib): use serge instead of serialize
Browse files Browse the repository at this point in the history
However, for some reason, the `Serialize/Deserialize` macros don't work
for me, even though they work just fine in the respective tests of
the serge crate. What am I possibly doing wrong ?
  • Loading branch information
Byron committed Mar 20, 2015
1 parent b6ebb1e commit d3bb130
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/mako/Cargo.toml.mako
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ keywords = ["${name}", ${", ".join(estr(cargo.keywords))}]
hyper = "*"
mime = "*"
url = "*"
rustc-serialize = "*"
serde = "*"
serde_macros = "*"
yup-oauth2 = "*"
8 changes: 5 additions & 3 deletions src/mako/lib.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ ${lib.docs(c)}
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
// unused imports in fully featured APIs. Same with unused_mut ... .
#![allow(unused_imports, unused_mut)]

// Required for serde annotations
#![feature(custom_derive, plugin)]
#![plugin(serde_macros)]

extern crate hyper;
extern crate "rustc-serialize" as rustc_serialize;
extern crate serde;
extern crate "yup-oauth2" as oauth2;
extern crate mime;
extern crate url;
Expand All @@ -44,7 +46,7 @@ use std::borrow::BorrowMut;
use std::default::Default;
use std::collections::BTreeMap;
use std::marker::PhantomData;
use rustc_serialize::json;
use serde::json;
use std::io;
use std::fs;
use std::old_io::timer::sleep;
Expand Down
6 changes: 3 additions & 3 deletions src/mako/lib/mbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ else {
% if request_value:
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
let mut request_value_reader = io::Cursor::new(json::encode(&self.${property(REQUEST_VALUE_PROPERTY_NAME)}).unwrap().into_bytes());
let mut request_value_reader = io::Cursor::new(json::to_vec(&self.${property(REQUEST_VALUE_PROPERTY_NAME)}).unwrap());
let request_size = request_value_reader.seek(io::SeekFrom::End(0)).unwrap();
request_value_reader.seek(io::SeekFrom::Start(0)).unwrap();
% endif
Expand Down Expand Up @@ -727,7 +727,7 @@ else {
if !res.status.is_success() {
let mut json_err = String::new();
res.read_to_string(&mut json_err).unwrap();
let error_info: cmn::JsonServerError = json::decode(&json_err).unwrap();
let error_info: cmn::JsonServerError = json::from_str(&json_err).unwrap();
if let oauth2::Retry::After(d) = dlg.http_failure(&res, error_info) {
sleep(d);
continue;
Expand All @@ -744,7 +744,7 @@ if enable_resource_parsing \
{
let mut json_response = String::new();
res.read_to_string(&mut json_response).unwrap();
(res, json::decode(&json_response).unwrap())
(res, json::from_str(&json_response).unwrap())
}\
% if supports_download:
else { (res, Default::default()) }\
Expand Down
8 changes: 4 additions & 4 deletions src/mako/lib/schema.mako
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ ${struct};
traits = ['Default', 'Clone', 'Debug']
if REQUEST_MARKER_TRAIT in markers:
traits.append('RustcEncodable')
traits.append('Serialize')
if RESPONSE_MARKER_TRAIT in markers:
traits.append('RustcDecodable')
traits.append('Deserialize')
## waiting for Default: https://github.com/rust-lang/rustc-serialize/issues/71
if s.type == 'any':
Expand All @@ -58,11 +58,11 @@ ${_new_object(s, s.items.get('properties'), c)}\
% endif ## array item != 'object'
% elif s.type == 'any':
## waiting for Default: https://github.com/rust-lang/rustc-serialize/issues/71
pub struct ${s_type}(rustc_serialize::json::Json);
pub struct ${s_type}(json::Value);
impl Default for ${s_type} {
fn default() -> ${s_type} {
${s_type}(rustc_serialize::json::Json::Null)
${s_type}(json::Value::Null)
}
}
% else:
Expand Down
2 changes: 1 addition & 1 deletion src/mako/lib/util.mako
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ${util.library_to_crate_name(util.library_name(name, version))}\
<%def name="test_prelude()">\
extern crate hyper;
extern crate "yup-oauth2" as oauth2;
extern crate "rustc-serialize" as rustc_serialize;
extern crate serde;
extern crate "${self.crate_name()}" as ${self.library_name()};
</%def>

Expand Down
2 changes: 1 addition & 1 deletion src/rust/cmn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<T: Seek + Read> ReadSeek for T {}


/// A utility type which can decode a server response that indicates error
#[derive(RustcDecodable)]
#[derive(Deserialize)]
pub struct JsonServerError {
error: String,
error_description: Option<String>
Expand Down
5 changes: 3 additions & 2 deletions src/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#![feature(core,io,old_path)]
#![feature(core,io,old_path, custom_derive, plugin)]
#![allow(dead_code, deprecated, unused_features)]
//! library with code shared by all generated implementations
#![plugin(serde_macros)]
extern crate hyper;
extern crate mime;
extern crate "rustc-serialize" as rustc_serialize;
extern crate "yup-oauth2" as oauth2;
extern crate serde;

// just pull it in the check if it compiles
mod cmn;
Expand Down

0 comments on commit d3bb130

Please sign in to comment.