From 21c94468908c00c891a9af8da0f9745312433725 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 18 Oct 2016 22:15:54 -0700 Subject: [PATCH] Update benchmarks to serde 0.8 --- testing/benches/bench.rs | 1 + testing/benches/bench_enum.rs | 42 ++++++++++++++++++++++++++++++++- testing/benches/bench_map.rs | 7 ++++++ testing/benches/bench_struct.rs | 6 +++++ testing/benches/bench_vec.rs | 14 +++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/testing/benches/bench.rs b/testing/benches/bench.rs index e5b10c57..80ebadac 100644 --- a/testing/benches/bench.rs +++ b/testing/benches/bench.rs @@ -3,6 +3,7 @@ #![cfg_attr(feature = "clippy", plugin(clippy))] extern crate rustc_serialize; +#[macro_use] extern crate serde; extern crate test; diff --git a/testing/benches/bench_enum.rs b/testing/benches/bench_enum.rs index 8badbb49..0e591c5b 100644 --- a/testing/benches/bench_enum.rs +++ b/testing/benches/bench_enum.rs @@ -251,7 +251,7 @@ mod decoder { mod deserializer { use super::{Animal, Error}; - use serde::de; + use serde::de::{self, Deserialize}; #[derive(Debug)] enum State { @@ -336,6 +336,12 @@ mod deserializer { } } } + + forward_to_deserialize! { + bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 char str + string unit option seq seq_fixed_size bytes map unit_struct + newtype_struct tuple_struct struct struct_field tuple ignored_any + } } struct DogVisitor<'a> { @@ -354,6 +360,24 @@ mod deserializer { fn visit_unit(&mut self) -> Result<(), Error> { de::Deserialize::deserialize(self.de) } + + fn visit_newtype(&mut self) -> Result + where T: Deserialize + { + Err(de::Error::invalid_type(de::Type::TupleVariant)) + } + + fn visit_tuple(&mut self, _len: usize, _visitor: V) -> Result + where V: de::Visitor + { + Err(de::Error::invalid_type(de::Type::TupleVariant)) + } + + fn visit_struct(&mut self, _fields: &'static [&'static str], _visitor: V) -> Result + where V: de::Visitor + { + Err(de::Error::invalid_type(de::Type::StructVariant)) + } } struct FrogVisitor<'a> { @@ -377,6 +401,22 @@ mod deserializer { { visitor.visit_seq(self) } + + fn visit_unit(&mut self) -> Result<(), Error> { + Err(de::Error::invalid_type(de::Type::UnitVariant)) + } + + fn visit_newtype(&mut self) -> Result + where T: Deserialize + { + Err(de::Error::invalid_type(de::Type::TupleVariant)) + } + + fn visit_struct(&mut self, _fields: &'static [&'static str], _visitor: V) -> Result + where V: de::Visitor + { + Err(de::Error::invalid_type(de::Type::StructVariant)) + } } impl<'a> de::SeqVisitor for FrogVisitor<'a> { diff --git a/testing/benches/bench_map.rs b/testing/benches/bench_map.rs index 32bc4415..bd2bb70f 100644 --- a/testing/benches/bench_map.rs +++ b/testing/benches/bench_map.rs @@ -286,6 +286,13 @@ mod deserializer { } } } + + forward_to_deserialize! { + bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 char str + string unit option seq seq_fixed_size bytes map unit_struct + newtype_struct tuple_struct struct struct_field tuple enum + ignored_any + } } impl de::MapVisitor for IsizeDeserializer { diff --git a/testing/benches/bench_struct.rs b/testing/benches/bench_struct.rs index 82b189e1..305de666 100644 --- a/testing/benches/bench_struct.rs +++ b/testing/benches/bench_struct.rs @@ -447,6 +447,12 @@ mod deserializer { } } } + + forward_to_deserialize! { + bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 char str + string unit option seq seq_fixed_size bytes map unit_struct + newtype_struct tuple_struct struct_field tuple enum ignored_any + } } struct OuterMapVisitor<'a> { diff --git a/testing/benches/bench_vec.rs b/testing/benches/bench_vec.rs index 96a4e637..eb71fae9 100644 --- a/testing/benches/bench_vec.rs +++ b/testing/benches/bench_vec.rs @@ -411,6 +411,13 @@ mod deserializer { } } } + + forward_to_deserialize! { + bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 char str + string unit option seq seq_fixed_size bytes map unit_struct + newtype_struct tuple_struct struct struct_field tuple enum + ignored_any + } } impl de::SeqVisitor for Deserializer { @@ -470,6 +477,13 @@ mod deserializer { } } } + + forward_to_deserialize! { + bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 char str + string unit option seq seq_fixed_size bytes map unit_struct + newtype_struct tuple_struct struct struct_field tuple enum + ignored_any + } } impl de::SeqVisitor for Deserializer {