diff --git a/serde2/serde2_macros/src/lib.rs b/serde2/serde2_macros/src/lib.rs index 04bf2564..12f00078 100644 --- a/serde2/serde2_macros/src/lib.rs +++ b/serde2/serde2_macros/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(plugin_registrar, quote)] +#![feature(plugin_registrar, quote, unboxed_closures)] extern crate syntax; extern crate rustc; @@ -62,8 +62,7 @@ fn expand_deriving_serialize<>(cx: &mut ExtCtxt, sp: Span, mitem: &MetaItem, item: &Item, - push: |P|) //where - //F: FnOnce(P) + mut push: Box)>) { let inline = cx.meta_word(sp, token::InternedString::new("inline")); let attrs = vec!(cx.attribute(sp, inline)); @@ -80,12 +79,11 @@ fn expand_deriving_serialize<>(cx: &mut ExtCtxt, generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec![ - ("__S", None, vec![]), - ("__R", None, vec![]), - ("__E", None, vec![]), + ("__S", vec![]), + ("__R", vec![]), + ("__E", vec![]), ( "__V", - None, vec![ Path::new_( vec!["serde2", "ser", "Visitor"], @@ -130,7 +128,7 @@ fn expand_deriving_serialize<>(cx: &mut ExtCtxt, ] }; - trait_def.expand(cx, mitem, item, |item| push(item)) + trait_def.expand(cx, mitem, item, |item| push.call_mut((item,))) } fn serialize_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> P { diff --git a/serde2/src/json/ser.rs b/serde2/src/json/ser.rs index 57fa3c3e..52895fe3 100644 --- a/serde2/src/json/ser.rs +++ b/serde2/src/json/ser.rs @@ -1,7 +1,7 @@ use std::f64; use std::io::{mod, ByRefWriter, IoError}; -use std::num::{Float, FPNaN, FPInfinite}; -use std::str::Utf8Error; +use std::num::{Float, FpCategory}; +use std::string::FromUtf8Error; use ser; use ser::Serializer; @@ -225,7 +225,7 @@ pub fn escape_char(wr: &mut W, value: char) -> Result<(), IoError fn fmt_f64_or_null(wr: &mut W, value: f64) -> Result<(), IoError> { match value.classify() { - FPNaN | FPInfinite => wr.write_str("null"), + FpCategory::Nan | FpCategory::Infinite => wr.write_str("null"), _ => wr.write_str(f64::to_str_digits(value, 6).as_slice()), } } @@ -252,7 +252,7 @@ pub fn to_vec< #[inline] pub fn to_string< T: ser::Serialize, ->(value: &T) -> Result, Utf8Error)>, IoError> { +>(value: &T) -> Result, IoError> { let vec = try!(to_vec(value)); Ok(String::from_utf8(vec)) } diff --git a/serde_macros/src/lib.rs b/serde_macros/src/lib.rs index 863dc7a4..4aef1ab5 100644 --- a/serde_macros/src/lib.rs +++ b/serde_macros/src/lib.rs @@ -1,7 +1,7 @@ #![crate_name = "serde_macros"] #![crate_type = "dylib"] -#![feature(plugin_registrar, quote)] +#![feature(plugin_registrar, quote, unboxed_closures)] extern crate syntax; extern crate rustc; @@ -70,7 +70,7 @@ fn expand_deriving_serialize(cx: &mut ExtCtxt, sp: Span, mitem: &MetaItem, item: &Item, - push: |P|) { + mut push: Box)>) { let inline = cx.meta_word(sp, token::InternedString::new("inline")); let attrs = vec!(cx.attribute(sp, inline)); @@ -83,10 +83,10 @@ fn expand_deriving_serialize(cx: &mut ExtCtxt, additional_bounds: Vec::new(), generics: LifetimeBounds { lifetimes: Vec::new(), - bounds: vec!(("__S", None, vec!(Path::new_( + bounds: vec!(("__S", vec!(Path::new_( vec!("serde", "ser", "Serializer"), None, vec!(box Literal(Path::new_local("__E"))), true))), - ("__E", None, vec!())) + ("__E", vec!())) }, methods: vec!( MethodDef { @@ -113,7 +113,7 @@ fn expand_deriving_serialize(cx: &mut ExtCtxt, }) }; - trait_def.expand(cx, mitem, item, |item| push(item)) + trait_def.expand(cx, mitem, item, |item| push.call_mut((item,))) } fn serialize_substructure(cx: &ExtCtxt, @@ -199,7 +199,7 @@ pub fn expand_deriving_deserialize(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, item: &Item, - push: |P|) { + mut push: Box)>) { let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -209,10 +209,10 @@ pub fn expand_deriving_deserialize(cx: &mut ExtCtxt, additional_bounds: Vec::new(), generics: LifetimeBounds { lifetimes: Vec::new(), - bounds: vec!(("__D", None, vec!(Path::new_( + bounds: vec!(("__D", vec!(Path::new_( vec!("serde", "de", "Deserializer"), None, vec!(box Literal(Path::new_local("__E"))), true))), - ("__E", None, vec!())) + ("__E", vec!())) }, methods: vec!( MethodDef { @@ -244,7 +244,7 @@ pub fn expand_deriving_deserialize(cx: &mut ExtCtxt, }) }; - trait_def.expand(cx, mitem, item, |item| push(item)) + trait_def.expand(cx, mitem, item, |item| push.call_mut((item,))) } fn deserialize_substructure(cx: &mut ExtCtxt, diff --git a/src/json/ser.rs b/src/json/ser.rs index ac07b677..2478c813 100644 --- a/src/json/ser.rs +++ b/src/json/ser.rs @@ -1,8 +1,8 @@ use std::f32; use std::f64; -use std::num::{Float, FPNaN, FPInfinite}; +use std::num::{Float, FpCategory}; use std::io::{IoError, IoResult}; -use std::str::Utf8Error; +use std::string::FromUtf8Error; use ser::Serialize; use ser; @@ -52,14 +52,14 @@ fn escape_char(wr: &mut W, v: char) -> IoResult<()> { fn fmt_f32_or_null(wr: &mut W, v: f32) -> IoResult<()> { match v.classify() { - FPNaN | FPInfinite => wr.write_str("null"), + FpCategory::Nan | FpCategory::Infinite => wr.write_str("null"), _ => wr.write_str(f32::to_str_digits(v, 6).as_slice()), } } fn fmt_f64_or_null(wr: &mut W, v: f64) -> IoResult<()> { match v.classify() { - FPNaN | FPInfinite => wr.write_str("null"), + FpCategory::Nan | FpCategory::Infinite => wr.write_str("null"), _ => wr.write_str(f64::to_str_digits(v, 6).as_slice()), } } @@ -600,7 +600,7 @@ pub fn to_vec< #[inline] pub fn to_string< T: Serialize>, IoError> ->(value: &T) -> Result, Utf8Error)> { +>(value: &T) -> Result { let buf = to_vec(value); String::from_utf8(buf) } @@ -629,7 +629,7 @@ pub fn to_pretty_vec< /// Encode the specified struct into a json `String` buffer. pub fn to_pretty_string< T: Serialize>, IoError> ->(value: &T) -> Result, Utf8Error)> { +>(value: &T) -> Result { let buf = to_pretty_vec(value); String::from_utf8(buf) }