diff --git a/benches/bench_enum.rs b/benches/bench_enum.rs index 926951b6..9ded96c5 100644 --- a/benches/bench_enum.rs +++ b/benches/bench_enum.rs @@ -100,7 +100,9 @@ mod decoder { // Compound types: #[inline] - fn read_enum(&mut self, name: &str, f: |&mut AnimalDecoder| -> Result) -> Result { + fn read_enum(&mut self, name: &str, f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { match self.stack.pop() { Some(AnimalState(animal)) => { self.stack.push(AnimalState(animal)); @@ -115,7 +117,9 @@ mod decoder { } #[inline] - fn read_enum_variant(&mut self, names: &[&str], f: |&mut AnimalDecoder, uint| -> Result) -> Result { + fn read_enum_variant(&mut self, names: &[&str], f: F) -> Result where + F: FnOnce(&mut AnimalDecoder, uint) -> Result, + { let name = match self.stack.pop() { Some(AnimalState(Dog)) => "Dog", Some(AnimalState(Frog(x0, x1))) => { @@ -133,56 +137,100 @@ mod decoder { f(self, idx) } + #[inline] - fn read_enum_variant_arg(&mut self, _a_idx: uint, f: |&mut AnimalDecoder| -> Result) -> Result { + fn read_enum_variant_arg(&mut self, _a_idx: uint, f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { f(self) } - fn read_enum_struct_variant(&mut self, - _names: &[&str], - _f: |&mut AnimalDecoder, uint| -> Result) - -> Result { Err(SyntaxError) } - fn read_enum_struct_variant_field(&mut self, - _f_name: &str, - _f_idx: uint, - _f: |&mut AnimalDecoder| -> Result) - -> Result { Err(SyntaxError) } - fn read_struct(&mut self, _s_name: &str, _len: uint, _f: |&mut AnimalDecoder| -> Result) - -> Result { Err(SyntaxError) } - fn read_struct_field(&mut self, - _f_name: &str, - _f_idx: uint, - _f: |&mut AnimalDecoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_enum_struct_variant(&mut self, _names: &[&str], _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder, uint) -> Result, + { + Err(Error::SyntaxError) + } - fn read_tuple(&mut self, _len: uint, _f: |&mut AnimalDecoder| -> Result) -> Result { Err(SyntaxError) } - fn read_tuple_arg(&mut self, _a_idx: uint, _f: |&mut AnimalDecoder| -> Result) -> Result { Err(SyntaxError) } + fn read_enum_struct_variant_field(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { + Err(Error::SyntaxError) + } - fn read_tuple_struct(&mut self, - _s_name: &str, - _len: uint, - _f: |&mut AnimalDecoder| -> Result) - -> Result { Err(SyntaxError) } - fn read_tuple_struct_arg(&mut self, - _a_idx: uint, - _f: |&mut AnimalDecoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_struct(&mut self, _s_name: &str, _len: uint, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_struct_field(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple(&mut self, _len: uint, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_struct(&mut self, _s_name: &str, _len: uint, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_struct_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { + Err(Error::SyntaxError) + } // Specialized types: - fn read_option(&mut self, _f: |&mut AnimalDecoder, bool| -> Result) -> Result { Err(SyntaxError) } + fn read_option(&mut self, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder, bool) -> Result, + { + Err(SyntaxError) + } #[inline] - fn read_seq(&mut self, f: |&mut AnimalDecoder, uint| -> Result) -> Result { + fn read_seq(&mut self, f: F) -> Result where + F: FnOnce(&mut AnimalDecoder, uint) -> Result, + { f(self, 3) } + #[inline] - fn read_seq_elt(&mut self, _idx: uint, f: |&mut AnimalDecoder| -> Result) -> Result { + fn read_seq_elt(&mut self, _idx: uint, f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { f(self) } - fn read_map(&mut self, _f: |&mut AnimalDecoder, uint| -> Result) -> Result { Err(SyntaxError) } - fn read_map_elt_key(&mut self, _idx: uint, _f: |&mut AnimalDecoder| -> Result) -> Result { Err(SyntaxError) } - fn read_map_elt_val(&mut self, _idx: uint, _f: |&mut AnimalDecoder| -> Result) -> Result { Err(SyntaxError) } + fn read_map(&mut self, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder, uint) -> Result, + { + Err(SyntaxError) + } + + fn read_map_elt_key(&mut self, _idx: uint, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { + Err(SyntaxError) + } + + fn read_map_elt_val(&mut self, _idx: uint, _f: F) -> Result where + F: FnOnce(&mut AnimalDecoder) -> Result, + { + Err(SyntaxError) + } } } diff --git a/benches/bench_log.rs b/benches/bench_log.rs index 4c228241..ed7e181b 100644 --- a/benches/bench_log.rs +++ b/benches/bench_log.rs @@ -10,6 +10,7 @@ extern crate test; use std::io; use std::io::ByRefWriter; +use std::io::extensions::Bytes; use test::Bencher; use serde::de; @@ -776,6 +777,7 @@ fn bench_serializer_my_mem_writer0(b: &mut Bencher) { let mut serializer = json::Serializer::new(wr.by_ref()); log.serialize(&mut serializer).unwrap(); + let _json = serializer.unwrap(); }); } @@ -806,6 +808,7 @@ fn bench_serializer_my_mem_writer1(b: &mut Bencher) { let mut serializer = json::Serializer::new(wr.by_ref()); log.serialize(&mut serializer).unwrap(); + let _json = serializer.unwrap(); }); } @@ -1629,9 +1632,8 @@ fn bench_iter_manual_iter_deserializers(b: &mut Bencher) { #[test] fn test_iter_manual_reader_as_iter_deserializer() { - use std::io::extensions::Bytes; - - let iter = Bytes::new(&mut JSON_STR.as_bytes()) + let mut rdr = JSON_STR.as_bytes(); + let iter = Bytes::new(&mut rdr) .map(|x| x.unwrap()); let log = manual_iter_deserialize(iter); @@ -1641,12 +1643,11 @@ fn test_iter_manual_reader_as_iter_deserializer() { #[bench] fn bench_iter_manual_reader_as_iter_deserializer(b: &mut Bencher) { - use std::io::extensions::Bytes; - b.bytes = JSON_STR.len() as u64; b.iter(|| { - let iter = Bytes::new(&mut JSON_STR.as_bytes()) + let mut rdr = JSON_STR.as_bytes(); + let iter = Bytes::new(&mut rdr) .map(|x| x.unwrap()); let _ = manual_iter_deserialize(iter); @@ -1658,7 +1659,8 @@ fn bench_iter_manual_reader_as_iter_deserializers(b: &mut Bencher) { b.bytes = JSON_STR.len() as u64; for _ in range(0i, 10000) { - let iter = Bytes::new(&mut JSON_STR.as_bytes()) + let mut rdr = JSON_STR.as_bytes(); + let iter = Bytes::new(&mut rdr) .map(|x| x.unwrap()); let _ = manual_iter_deserialize(iter); diff --git a/benches/bench_map.rs b/benches/bench_map.rs index cc1643bc..e17e80f7 100644 --- a/benches/bench_map.rs +++ b/benches/bench_map.rs @@ -95,61 +95,102 @@ mod decoder { } // Compound types: - fn read_enum(&mut self, _name: &str, _f: |&mut IntDecoder| -> Result) -> Result { Err(SyntaxError) } + fn read_enum(&mut self, _name: &str, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } - fn read_enum_variant(&mut self, - _names: &[&str], - _f: |&mut IntDecoder, uint| -> Result) - -> Result { Err(SyntaxError) } - fn read_enum_variant_arg(&mut self, - _a_idx: uint, - _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_enum_variant(&mut self, _names: &[&str], _f: F) -> Result where + F: FnOnce(&mut IntDecoder, uint) -> Result, + { + Err(Error::SyntaxError) + } - fn read_enum_struct_variant(&mut self, - _names: &[&str], - _f: |&mut IntDecoder, uint| -> Result) - -> Result { Err(SyntaxError) } - fn read_enum_struct_variant_field(&mut self, - _f_name: &str, - _f_idx: uint, - _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_enum_variant_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } - fn read_struct(&mut self, _s_name: &str, _len: uint, _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } - fn read_struct_field(&mut self, - _f_name: &str, - _f_idx: uint, - _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_enum_struct_variant(&mut self, _names: &[&str], _f: F) -> Result where + F: FnOnce(&mut IntDecoder, uint) -> Result, + { + Err(Error::SyntaxError) + } - fn read_tuple(&mut self, _len: uint, _f: |&mut IntDecoder| -> Result) -> Result { Err(SyntaxError) } - fn read_tuple_arg(&mut self, _a_idx: uint, _f: |&mut IntDecoder| -> Result) -> Result { Err(SyntaxError) } + fn read_enum_struct_variant_field(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } - fn read_tuple_struct(&mut self, - _s_name: &str, - _len: uint, - _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } - fn read_tuple_struct_arg(&mut self, - _a_idx: uint, - _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_struct(&mut self, _s_name: &str, _len: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_struct_field(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple(&mut self, _len: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_struct(&mut self, _s_name: &str, _len: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_struct_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } // Specialized types: - fn read_option(&mut self, _f: |&mut IntDecoder, bool| -> Result) -> Result { Err(SyntaxError) } + fn read_option(&mut self, _f: F) -> Result where + F: FnOnce(&mut IntDecoder, bool) -> Result, + { + Err(SyntaxError) + } - fn read_seq(&mut self, _f: |&mut IntDecoder, uint| -> Result) -> Result { Err(SyntaxError) } - fn read_seq_elt(&mut self, _idx: uint, _f: |&mut IntDecoder| -> Result) -> Result { Err(SyntaxError) } + fn read_seq(&mut self, _f: F) -> Result where + F: FnOnce(&mut IntDecoder, uint) -> Result, + { + Err(SyntaxError) + } + + fn read_seq_elt(&mut self, _idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(SyntaxError) + } #[inline] - fn read_map(&mut self, f: |&mut IntDecoder, uint| -> Result) -> Result { + fn read_map(&mut self, f: F) -> Result where + F: FnOnce(&mut IntDecoder, uint) -> Result, + { let len = self.len; f(self, len) } #[inline] - fn read_map_elt_key(&mut self, _idx: uint, f: |&mut IntDecoder| -> Result) -> Result { + fn read_map_elt_key(&mut self, _idx: uint, f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { match self.iter.next() { Some((key, value)) => { self.stack.push(IntValue(value)); @@ -161,8 +202,11 @@ mod decoder { } } } + #[inline] - fn read_map_elt_val(&mut self, _idx: uint, f: |&mut IntDecoder| -> Result) -> Result { + fn read_map_elt_val(&mut self, _idx: uint, f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { f(self) } } diff --git a/benches/bench_struct.rs b/benches/bench_struct.rs index b818dae9..650d11d5 100644 --- a/benches/bench_struct.rs +++ b/benches/bench_struct.rs @@ -139,29 +139,40 @@ mod decoder { } // Compound types: - fn read_enum(&mut self, _name: &str, _f: |&mut OuterDecoder| -> Result) -> Result { Err(Error::SyntaxError("".to_string())) } + fn read_enum(&mut self, _name: &str, _f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { + Err(Error::SyntaxError("".to_string())) + } - fn read_enum_variant(&mut self, - _names: &[&str], - _f: |&mut OuterDecoder, uint| -> Result) - -> Result { Err(Error::SyntaxError("".to_string())) } - fn read_enum_variant_arg(&mut self, - _a_idx: uint, - _f: |&mut OuterDecoder| -> Result) - -> Result { Err(Error::SyntaxError("".to_string())) } + fn read_enum_variant(&mut self, _names: &[&str], _f: F) -> Result where + F: FnOnce(&mut OuterDecoder, uint) -> Result, + { + Err(Error::SyntaxError("".to_string())) + } - fn read_enum_struct_variant(&mut self, - _names: &[&str], - _f: |&mut OuterDecoder, uint| -> Result) - -> Result { Err(Error::SyntaxError("".to_string())) } - fn read_enum_struct_variant_field(&mut self, - _f_name: &str, - _f_idx: uint, - _f: |&mut OuterDecoder| -> Result) - -> Result { Err(Error::SyntaxError("".to_string())) } + fn read_enum_variant_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { + Err(Error::SyntaxError("".to_string())) + } + + fn read_enum_struct_variant(&mut self, _names: &[&str], _f: F) -> Result where + F: FnOnce(&mut OuterDecoder, uint) -> Result, + { + Err(Error::SyntaxError("".to_string())) + } + + fn read_enum_struct_variant_field(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { + Err(Error::SyntaxError("".to_string())) + } #[inline] - fn read_struct(&mut self, s_name: &str, _len: uint, f: |&mut OuterDecoder| -> Result) -> Result { + fn read_struct(&mut self, s_name: &str, _len: uint, f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { match self.stack.pop() { Some(OuterState(Outer { inner })) => { if s_name == "Outer" { @@ -191,7 +202,9 @@ mod decoder { } } #[inline] - fn read_struct_field(&mut self, f_name: &str, _f_idx: uint, f: |&mut OuterDecoder| -> Result) -> Result { + fn read_struct_field(&mut self, f_name: &str, _f_idx: uint, f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { match self.stack.pop() { Some(FieldState(name)) => { if f_name == name { @@ -204,22 +217,35 @@ mod decoder { } } - fn read_tuple(&mut self, _len: uint, _f: |&mut OuterDecoder| -> Result) -> Result { Err(Error::SyntaxError("".to_string())) } - fn read_tuple_arg(&mut self, _a_idx: uint, _f: |&mut OuterDecoder| -> Result) -> Result { Err(Error::SyntaxError("".to_string())) } + fn read_tuple(&mut self, _len: uint, _f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { + Err(Error::SyntaxError("".to_string())) + } - fn read_tuple_struct(&mut self, - _s_name: &str, - _len: uint, - _f: |&mut OuterDecoder| -> Result) - -> Result { Err(Error::SyntaxError("".to_string())) } - fn read_tuple_struct_arg(&mut self, - _a_idx: uint, - _f: |&mut OuterDecoder| -> Result) - -> Result { Err(Error::SyntaxError("".to_string())) } + fn read_tuple_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { + Err(Error::SyntaxError("".to_string())) + } + + fn read_tuple_struct(&mut self, _s_name: &str, _len: uint, _f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { + Err(Error::SyntaxError("".to_string())) + } + + fn read_tuple_struct_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { + Err(Error::SyntaxError("".to_string())) + } // Specialized types: #[inline] - fn read_option(&mut self, f: |&mut OuterDecoder, bool| -> Result) -> Result { + fn read_option(&mut self, f: F) -> Result where + F: FnOnce(&mut OuterDecoder, bool) -> Result, + { match self.stack.pop() { Some(OptionState(b)) => f(self, b), _ => Err(Error::SyntaxError("expected OptionState".to_string())), @@ -227,7 +253,9 @@ mod decoder { } #[inline] - fn read_seq(&mut self, f: |&mut OuterDecoder, uint| -> Result) -> Result { + fn read_seq(&mut self, f: F) -> Result where + F: FnOnce(&mut OuterDecoder, uint) -> Result, + { match self.stack.pop() { Some(VecState(value)) => { let len = value.len(); @@ -240,12 +268,16 @@ mod decoder { } } #[inline] - fn read_seq_elt(&mut self, _idx: uint, f: |&mut OuterDecoder| -> Result) -> Result { + fn read_seq_elt(&mut self, _idx: uint, f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { f(self) } #[inline] - fn read_map(&mut self, f: |&mut OuterDecoder, uint| -> Result) -> Result { + fn read_map(&mut self, f: F) -> Result where + F: FnOnce(&mut OuterDecoder, uint) -> Result, + { match self.stack.pop() { Some(MapState(map)) => { let len = map.len(); @@ -267,11 +299,16 @@ mod decoder { } } #[inline] - fn read_map_elt_key(&mut self, _idx: uint, f: |&mut OuterDecoder| -> Result) -> Result { + fn read_map_elt_key(&mut self, _idx: uint, f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { f(self) } + #[inline] - fn read_map_elt_val(&mut self, _idx: uint, f: |&mut OuterDecoder| -> Result) -> Result { + fn read_map_elt_val(&mut self, _idx: uint, f: F) -> Result where + F: FnOnce(&mut OuterDecoder) -> Result, + { f(self) } } diff --git a/benches/bench_vec.rs b/benches/bench_vec.rs index aca12fd4..6af27b25 100644 --- a/benches/bench_vec.rs +++ b/benches/bench_vec.rs @@ -77,64 +77,110 @@ mod decoder { fn read_str(&mut self) -> Result { Err(SyntaxError) } // Compound types: - fn read_enum(&mut self, _name: &str, _f: |&mut IntDecoder| -> Result) -> Result { Err(SyntaxError) } + fn read_enum(&mut self, _name: &str, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } - fn read_enum_variant(&mut self, - _names: &[&str], - _f: |&mut IntDecoder, uint| -> Result) - -> Result { Err(SyntaxError) } - fn read_enum_variant_arg(&mut self, - _a_idx: uint, - _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_enum_variant(&mut self, _names: &[&str], _f: F) -> Result where + F: FnOnce(&mut IntDecoder, uint) -> Result, + { + Err(Error::SyntaxError) + } - fn read_enum_struct_variant(&mut self, - _names: &[&str], - _f: |&mut IntDecoder, uint| -> Result) - -> Result { Err(SyntaxError) } - fn read_enum_struct_variant_field(&mut self, - _f_name: &str, - _f_idx: uint, - _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_enum_variant_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } - fn read_struct(&mut self, _s_name: &str, _len: uint, _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } - fn read_struct_field(&mut self, - _f_name: &str, - _f_idx: uint, - _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_enum_struct_variant(&mut self, _names: &[&str], _f: F) -> Result where + F: FnOnce(&mut IntDecoder, uint) -> Result, + { + Err(Error::SyntaxError) + } - fn read_tuple(&mut self, _len: uint, _f: |&mut IntDecoder| -> Result) -> Result { Err(SyntaxError) } - fn read_tuple_arg(&mut self, _a_idx: uint, _f: |&mut IntDecoder| -> Result) -> Result { Err(SyntaxError) } + fn read_enum_struct_variant_field(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } - fn read_tuple_struct(&mut self, - _s_name: &str, - _len: uint, - _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } - fn read_tuple_struct_arg(&mut self, - _a_idx: uint, - _f: |&mut IntDecoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_struct(&mut self, _s_name: &str, _len: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_struct_field(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple(&mut self, _len: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_struct(&mut self, _s_name: &str, _len: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_struct_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(Error::SyntaxError) + } // Specialized types: - fn read_option(&mut self, _f: |&mut IntDecoder, bool| -> Result) -> Result { Err(SyntaxError) } + fn read_option(&mut self, _f: F) -> Result where + F: FnOnce(&mut IntDecoder, bool) -> Result, + { + Err(SyntaxError) + } #[inline] - fn read_seq(&mut self, f: |&mut IntDecoder, uint| -> Result) -> Result { + fn read_seq(&mut self, f: F) -> Result where + F: FnOnce(&mut IntDecoder, uint) -> Result, + { let len = self.len; f(self, len) } #[inline] - fn read_seq_elt(&mut self, _idx: uint, f: |&mut IntDecoder| -> Result) -> Result { + fn read_seq_elt(&mut self, _idx: uint, f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { f(self) } - fn read_map(&mut self, _f: |&mut IntDecoder, uint| -> Result) -> Result { Err(SyntaxError) } - fn read_map_elt_key(&mut self, _idx: uint, _f: |&mut IntDecoder| -> Result) -> Result { Err(SyntaxError) } - fn read_map_elt_val(&mut self, _idx: uint, _f: |&mut IntDecoder| -> Result) -> Result { Err(SyntaxError) } + fn read_map(&mut self, _f: F) -> Result where + F: FnOnce(&mut IntDecoder, uint) -> Result, + { + Err(SyntaxError) + } + + fn read_map_elt_key(&mut self, _idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(SyntaxError) + } + + fn read_map_elt_val(&mut self, _idx: uint, _f: F) -> Result where + F: FnOnce(&mut IntDecoder) -> Result, + { + Err(SyntaxError) + } } @@ -184,64 +230,110 @@ mod decoder { fn read_str(&mut self) -> Result { Err(SyntaxError) } // Compound types: - fn read_enum(&mut self, _name: &str, _f: |&mut U8Decoder| -> Result) -> Result { Err(SyntaxError) } + fn read_enum(&mut self, _name: &str, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(Error::SyntaxError) + } - fn read_enum_variant(&mut self, - _names: &[&str], - _f: |&mut U8Decoder, uint| -> Result) - -> Result { Err(SyntaxError) } - fn read_enum_variant_arg(&mut self, - _a_idx: uint, - _f: |&mut U8Decoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_enum_variant(&mut self, _names: &[&str], _f: F) -> Result where + F: FnOnce(&mut U8Decoder, uint) -> Result, + { + Err(Error::SyntaxError) + } - fn read_enum_struct_variant(&mut self, - _names: &[&str], - _f: |&mut U8Decoder, uint| -> Result) - -> Result { Err(SyntaxError) } - fn read_enum_struct_variant_field(&mut self, - _f_name: &str, - _f_idx: uint, - _f: |&mut U8Decoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_enum_variant_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(Error::SyntaxError) + } - fn read_struct(&mut self, _s_name: &str, _len: uint, _f: |&mut U8Decoder| -> Result) - -> Result { Err(SyntaxError) } - fn read_struct_field(&mut self, - _f_name: &str, - _f_idx: uint, - _f: |&mut U8Decoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_enum_struct_variant(&mut self, _names: &[&str], _f: F) -> Result where + F: FnOnce(&mut U8Decoder, uint) -> Result, + { + Err(Error::SyntaxError) + } - fn read_tuple(&mut self, _len: uint, _f: |&mut U8Decoder| -> Result) -> Result { Err(SyntaxError) } - fn read_tuple_arg(&mut self, _a_idx: uint, _f: |&mut U8Decoder| -> Result) -> Result { Err(SyntaxError) } + fn read_enum_struct_variant_field(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(Error::SyntaxError) + } - fn read_tuple_struct(&mut self, - _s_name: &str, - _len: uint, - _f: |&mut U8Decoder| -> Result) - -> Result { Err(SyntaxError) } - fn read_tuple_struct_arg(&mut self, - _a_idx: uint, - _f: |&mut U8Decoder| -> Result) - -> Result { Err(SyntaxError) } + fn read_struct(&mut self, _s_name: &str, _len: uint, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_struct_field(&mut self, _f_name: &str, _f_idx: uint, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple(&mut self, _len: uint, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_struct(&mut self, _s_name: &str, _len: uint, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(Error::SyntaxError) + } + + fn read_tuple_struct_arg(&mut self, _a_idx: uint, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(Error::SyntaxError) + } // Specialized types: - fn read_option(&mut self, _f: |&mut U8Decoder, bool| -> Result) -> Result { Err(SyntaxError) } + fn read_option(&mut self, _f: F) -> Result where + F: FnOnce(&mut U8Decoder, bool) -> Result, + { + Err(SyntaxError) + } #[inline] - fn read_seq(&mut self, f: |&mut U8Decoder, uint| -> Result) -> Result { + fn read_seq(&mut self, f: F) -> Result where + F: FnOnce(&mut U8Decoder, uint) -> Result, + { let len = self.len; f(self, len) } #[inline] - fn read_seq_elt(&mut self, _idx: uint, f: |&mut U8Decoder| -> Result) -> Result { + fn read_seq_elt(&mut self, _idx: uint, f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { f(self) } - fn read_map(&mut self, _f: |&mut U8Decoder, uint| -> Result) -> Result { Err(SyntaxError) } - fn read_map_elt_key(&mut self, _idx: uint, _f: |&mut U8Decoder| -> Result) -> Result { Err(SyntaxError) } - fn read_map_elt_val(&mut self, _idx: uint, _f: |&mut U8Decoder| -> Result) -> Result { Err(SyntaxError) } + fn read_map(&mut self, _f: F) -> Result where + F: FnOnce(&mut U8Decoder, uint) -> Result, + { + Err(SyntaxError) + } + + fn read_map_elt_key(&mut self, _idx: uint, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(SyntaxError) + } + + fn read_map_elt_val(&mut self, _idx: uint, _f: F) -> Result where + F: FnOnce(&mut U8Decoder) -> Result, + { + Err(SyntaxError) + } } } diff --git a/serde2/serde2_macros/src/lib.rs b/serde2/serde2_macros/src/lib.rs index f4fbe999..04bf2564 100644 --- a/serde2/serde2_macros/src/lib.rs +++ b/serde2/serde2_macros/src/lib.rs @@ -13,7 +13,7 @@ use syntax::ast::{ }; use syntax::ast; use syntax::codemap::Span; -use syntax::ext::base::{ExtCtxt, Decorator}; +use syntax::ext::base::{ExtCtxt, Decorator, ItemDecorator}; use syntax::ext::build::AstBuilder; use syntax::ext::deriving::generic::{ EnumMatching, @@ -58,12 +58,13 @@ pub fn plugin_registrar(reg: &mut Registry) { */ } -fn expand_deriving_serialize(cx: &mut ExtCtxt, +fn expand_deriving_serialize<>(cx: &mut ExtCtxt, sp: Span, mitem: &MetaItem, item: &Item, - push: |P|) { - + push: |P|) //where + //F: FnOnce(P) +{ let inline = cx.meta_word(sp, token::InternedString::new("inline")); let attrs = vec!(cx.attribute(sp, inline)); @@ -129,7 +130,7 @@ fn expand_deriving_serialize(cx: &mut ExtCtxt, ] }; - trait_def.expand(cx, mitem, item, push) + trait_def.expand(cx, mitem, item, |item| push(item)) } fn serialize_substructure(cx: &ExtCtxt, span: Span, substr: &Substructure) -> P { diff --git a/serde_macros/src/lib.rs b/serde_macros/src/lib.rs index a794d08a..863dc7a4 100644 --- a/serde_macros/src/lib.rs +++ b/serde_macros/src/lib.rs @@ -23,7 +23,7 @@ use syntax::ast::{ use syntax::ast; use syntax::attr; use syntax::codemap::Span; -use syntax::ext::base::{ExtCtxt, Decorator}; +use syntax::ext::base::{ExtCtxt, Decorator, ItemDecorator}; use syntax::ext::build::AstBuilder; use syntax::ext::deriving::generic::{ EnumMatching, @@ -113,7 +113,7 @@ fn expand_deriving_serialize(cx: &mut ExtCtxt, }) }; - trait_def.expand(cx, mitem, item, push) + trait_def.expand(cx, mitem, item, |item| push(item)) } fn serialize_substructure(cx: &ExtCtxt, @@ -244,7 +244,7 @@ pub fn expand_deriving_deserialize(cx: &mut ExtCtxt, }) }; - trait_def.expand(cx, mitem, item, push) + trait_def.expand(cx, mitem, item, |item| push(item)) } fn deserialize_substructure(cx: &mut ExtCtxt,