From e05737a93c3fc83f4530d89b0891db76c9a43ec6 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 19 Oct 2015 13:06:30 +0200 Subject: [PATCH] chore(tests): update unit tests and benchmarks to visit -> (de)serialize renaming --- serde_tests/benches/bench_enum.rs | 4 +- serde_tests/benches/bench_map.rs | 10 ++-- serde_tests/benches/bench_struct.rs | 4 +- serde_tests/benches/bench_vec.rs | 4 +- serde_tests/tests/test_bytes.rs | 34 ++++++------ serde_tests/tests/token.rs | 82 ++++++++++++++--------------- 6 files changed, 69 insertions(+), 69 deletions(-) diff --git a/serde_tests/benches/bench_enum.rs b/serde_tests/benches/bench_enum.rs index 0367df8b68..6af46b959f 100644 --- a/serde_tests/benches/bench_enum.rs +++ b/serde_tests/benches/bench_enum.rs @@ -262,7 +262,7 @@ mod deserializer { type Error = Error; #[inline] - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.stack.pop() { @@ -288,7 +288,7 @@ mod deserializer { } #[inline] - fn visit_enum(&mut self, + fn deserialize_enum(&mut self, _name: &str, _variants: &[&str], mut visitor: V) -> Result diff --git a/serde_tests/benches/bench_map.rs b/serde_tests/benches/bench_map.rs index 71d0ab923f..3b8473055f 100644 --- a/serde_tests/benches/bench_map.rs +++ b/serde_tests/benches/bench_map.rs @@ -252,7 +252,7 @@ mod deserializer { impl de::Deserializer for IsizeDeserializer { type Error = Error; - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.stack.pop() { @@ -399,7 +399,7 @@ fn bench_decoder_000(b: &mut Bencher) { fn bench_decoder_003(b: &mut Bencher) { b.iter(|| { let mut m: HashMap = HashMap::new(); - for i in (0 .. 3) { + for i in 0 .. 3 { m.insert(i.to_string(), i); } run_decoder(decoder::IsizeDecoder::new(m.clone()), m) @@ -410,7 +410,7 @@ fn bench_decoder_003(b: &mut Bencher) { fn bench_decoder_100(b: &mut Bencher) { b.iter(|| { let mut m: HashMap = HashMap::new(); - for i in (0 .. 100) { + for i in 0 .. 100 { m.insert(i.to_string(), i); } run_decoder(decoder::IsizeDecoder::new(m.clone()), m) @@ -439,7 +439,7 @@ fn bench_deserializer_000(b: &mut Bencher) { fn bench_deserializer_003(b: &mut Bencher) { b.iter(|| { let mut m: HashMap = HashMap::new(); - for i in (0 .. 3) { + for i in 0 .. 3 { m.insert(i.to_string(), i); } run_deserializer(deserializer::IsizeDeserializer::new(m.clone()), m) @@ -450,7 +450,7 @@ fn bench_deserializer_003(b: &mut Bencher) { fn bench_deserializer_100(b: &mut Bencher) { b.iter(|| { let mut m: HashMap = HashMap::new(); - for i in (0 .. 100) { + for i in 0 .. 100 { m.insert(i.to_string(), i); } run_deserializer(deserializer::IsizeDeserializer::new(m.clone()), m) diff --git a/serde_tests/benches/bench_struct.rs b/serde_tests/benches/bench_struct.rs index 0e53d1a3f0..fa9142cb15 100644 --- a/serde_tests/benches/bench_struct.rs +++ b/serde_tests/benches/bench_struct.rs @@ -356,7 +356,7 @@ mod deserializer { impl de::Deserializer for OuterDeserializer { type Error = Error; - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.stack.pop() { @@ -398,7 +398,7 @@ mod deserializer { } } - fn visit_struct(&mut self, + fn deserialize_struct(&mut self, name: &str, _fields: &'static [&'static str], mut visitor: V) -> Result diff --git a/serde_tests/benches/bench_vec.rs b/serde_tests/benches/bench_vec.rs index c0ec800ce3..13822bc17c 100644 --- a/serde_tests/benches/bench_vec.rs +++ b/serde_tests/benches/bench_vec.rs @@ -378,7 +378,7 @@ mod deserializer { type Error = Error; #[inline] - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.state { @@ -437,7 +437,7 @@ mod deserializer { type Error = Error; #[inline] - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.state { diff --git a/serde_tests/tests/test_bytes.rs b/serde_tests/tests/test_bytes.rs index 1203fed49e..4ddcb0d6f3 100644 --- a/serde_tests/tests/test_bytes.rs +++ b/serde_tests/tests/test_bytes.rs @@ -34,74 +34,74 @@ impl BytesSerializer { impl serde::Serializer for BytesSerializer { type Error = Error; - fn visit_unit(&mut self) -> Result<(), Error> { + fn serialize_unit(&mut self) -> Result<(), Error> { Err(Error) } - fn visit_bool(&mut self, _v: bool) -> Result<(), Error> { + fn serialize_bool(&mut self, _v: bool) -> Result<(), Error> { Err(Error) } - fn visit_i64(&mut self, _v: i64) -> Result<(), Error> { + fn serialize_i64(&mut self, _v: i64) -> Result<(), Error> { Err(Error) } - fn visit_u64(&mut self, _v: u64) -> Result<(), Error> { + fn serialize_u64(&mut self, _v: u64) -> Result<(), Error> { Err(Error) } - fn visit_f32(&mut self, _v: f32) -> Result<(), Error> { + fn serialize_f32(&mut self, _v: f32) -> Result<(), Error> { Err(Error) } - fn visit_f64(&mut self, _v: f64) -> Result<(), Error> { + fn serialize_f64(&mut self, _v: f64) -> Result<(), Error> { Err(Error) } - fn visit_char(&mut self, _v: char) -> Result<(), Error> { + fn serialize_char(&mut self, _v: char) -> Result<(), Error> { Err(Error) } - fn visit_str(&mut self, _v: &str) -> Result<(), Error> { + fn serialize_str(&mut self, _v: &str) -> Result<(), Error> { Err(Error) } - fn visit_none(&mut self) -> Result<(), Error> { + fn serialize_none(&mut self) -> Result<(), Error> { Err(Error) } - fn visit_some(&mut self, _value: V) -> Result<(), Error> + fn serialize_some(&mut self, _value: V) -> Result<(), Error> where V: serde::Serialize, { Err(Error) } - fn visit_seq(&mut self, _visitor: V) -> Result<(), Error> + fn serialize_seq(&mut self, _visitor: V) -> Result<(), Error> where V: serde::ser::SeqVisitor, { Err(Error) } - fn visit_seq_elt(&mut self, _value: T) -> Result<(), Error> + fn serialize_seq_elt(&mut self, _value: T) -> Result<(), Error> where T: serde::Serialize { Err(Error) } - fn visit_map(&mut self, _visitor: V) -> Result<(), Error> + fn serialize_map(&mut self, _visitor: V) -> Result<(), Error> where V: serde::ser::MapVisitor, { Err(Error) } - fn visit_map_elt(&mut self, _key: K, _value: V) -> Result<(), Error> + fn serialize_map_elt(&mut self, _key: K, _value: V) -> Result<(), Error> where K: serde::Serialize, V: serde::Serialize, { Err(Error) } - fn visit_bytes(&mut self, bytes: &[u8]) -> Result<(), Error> { + fn serialize_bytes(&mut self, bytes: &[u8]) -> Result<(), Error> { assert_eq!(self.bytes, bytes); Ok(()) } @@ -124,13 +124,13 @@ impl BytesDeserializer { impl serde::Deserializer for BytesDeserializer { type Error = Error; - fn visit(&mut self, _visitor: V) -> Result + fn deserialize(&mut self, _visitor: V) -> Result where V: serde::de::Visitor, { Err(Error) } - fn visit_bytes(&mut self, mut visitor: V) -> Result + fn deserialize_bytes(&mut self, mut visitor: V) -> Result where V: serde::de::Visitor, { visitor.visit_byte_buf(self.bytes.take().unwrap()) diff --git a/serde_tests/tests/token.rs b/serde_tests/tests/token.rs index 4815dd1d43..d97783b571 100644 --- a/serde_tests/tests/token.rs +++ b/serde_tests/tests/token.rs @@ -89,12 +89,12 @@ impl<'a, I> ser::Serializer for Serializer { type Error = (); - fn visit_unit(&mut self) -> Result<(), ()> { + fn serialize_unit(&mut self) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::Unit)); Ok(()) } - fn visit_newtype_variant(&mut self, + fn serialize_newtype_variant(&mut self, name: &str, _variant_index: usize, variant: &str, @@ -105,12 +105,12 @@ impl<'a, I> ser::Serializer for Serializer value.serialize(self) } - fn visit_unit_struct(&mut self, name: &str) -> Result<(), ()> { + fn serialize_unit_struct(&mut self, name: &str) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::UnitStruct(name))); Ok(()) } - fn visit_unit_variant(&mut self, + fn serialize_unit_variant(&mut self, name: &str, _variant_index: usize, variant: &str) -> Result<(), ()> { @@ -119,87 +119,87 @@ impl<'a, I> ser::Serializer for Serializer Ok(()) } - fn visit_bool(&mut self, v: bool) -> Result<(), ()> { + fn serialize_bool(&mut self, v: bool) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::Bool(v))); Ok(()) } - fn visit_isize(&mut self, v: isize) -> Result<(), ()> { + fn serialize_isize(&mut self, v: isize) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::Isize(v))); Ok(()) } - fn visit_i8(&mut self, v: i8) -> Result<(), ()> { + fn serialize_i8(&mut self, v: i8) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::I8(v))); Ok(()) } - fn visit_i16(&mut self, v: i16) -> Result<(), ()> { + fn serialize_i16(&mut self, v: i16) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::I16(v))); Ok(()) } - fn visit_i32(&mut self, v: i32) -> Result<(), ()> { + fn serialize_i32(&mut self, v: i32) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::I32(v))); Ok(()) } - fn visit_i64(&mut self, v: i64) -> Result<(), ()> { + fn serialize_i64(&mut self, v: i64) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::I64(v))); Ok(()) } - fn visit_usize(&mut self, v: usize) -> Result<(), ()> { + fn serialize_usize(&mut self, v: usize) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::Usize(v))); Ok(()) } - fn visit_u8(&mut self, v: u8) -> Result<(), ()> { + fn serialize_u8(&mut self, v: u8) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::U8(v))); Ok(()) } - fn visit_u16(&mut self, v: u16) -> Result<(), ()> { + fn serialize_u16(&mut self, v: u16) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::U16(v))); Ok(()) } - fn visit_u32(&mut self, v: u32) -> Result<(), ()> { + fn serialize_u32(&mut self, v: u32) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::U32(v))); Ok(()) } - fn visit_u64(&mut self, v: u64) -> Result<(), ()> { + fn serialize_u64(&mut self, v: u64) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::U64(v))); Ok(()) } - fn visit_f32(&mut self, v: f32) -> Result<(), ()> { + fn serialize_f32(&mut self, v: f32) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::F32(v))); Ok(()) } - fn visit_f64(&mut self, v: f64) -> Result<(), ()> { + fn serialize_f64(&mut self, v: f64) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::F64(v))); Ok(()) } - fn visit_char(&mut self, v: char) -> Result<(), ()> { + fn serialize_char(&mut self, v: char) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::Char(v))); Ok(()) } - fn visit_str(&mut self, v: &str) -> Result<(), ()> { + fn serialize_str(&mut self, v: &str) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::Str(v))); Ok(()) } - fn visit_none(&mut self) -> Result<(), ()> { + fn serialize_none(&mut self) -> Result<(), ()> { assert_eq!(self.tokens.next(), Some(&Token::Option(false))); Ok(()) } - fn visit_some(&mut self, value: V) -> Result<(), ()> + fn serialize_some(&mut self, value: V) -> Result<(), ()> where V: ser::Serialize, { assert_eq!(self.tokens.next(), Some(&Token::Option(true))); @@ -207,7 +207,7 @@ impl<'a, I> ser::Serializer for Serializer } - fn visit_seq(&mut self, visitor: V) -> Result<(), ()> + fn serialize_seq(&mut self, visitor: V) -> Result<(), ()> where V: ser::SeqVisitor { let len = visitor.len(); @@ -217,7 +217,7 @@ impl<'a, I> ser::Serializer for Serializer self.visit_sequence(visitor) } - fn visit_newtype_struct(&mut self, + fn serialize_newtype_struct(&mut self, name: &'static str, value: T) -> Result<(), ()> where T: ser::Serialize, @@ -226,7 +226,7 @@ impl<'a, I> ser::Serializer for Serializer value.serialize(self) } - fn visit_tuple_struct(&mut self, name: &str, visitor: V) -> Result<(), ()> + fn serialize_tuple_struct(&mut self, name: &str, visitor: V) -> Result<(), ()> where V: ser::SeqVisitor { let len = visitor.len(); @@ -236,7 +236,7 @@ impl<'a, I> ser::Serializer for Serializer self.visit_sequence(visitor) } - fn visit_tuple_variant(&mut self, + fn serialize_tuple_variant(&mut self, name: &str, _variant_index: usize, variant: &str, @@ -250,14 +250,14 @@ impl<'a, I> ser::Serializer for Serializer self.visit_sequence(visitor) } - fn visit_seq_elt(&mut self, value: T) -> Result<(), ()> + fn serialize_seq_elt(&mut self, value: T) -> Result<(), ()> where T: ser::Serialize { assert_eq!(self.tokens.next(), Some(&Token::SeqSep)); value.serialize(self) } - fn visit_map(&mut self, visitor: V) -> Result<(), ()> + fn serialize_map(&mut self, visitor: V) -> Result<(), ()> where V: ser::MapVisitor { let len = visitor.len(); @@ -267,7 +267,7 @@ impl<'a, I> ser::Serializer for Serializer self.visit_mapping(visitor) } - fn visit_struct(&mut self, name: &str, visitor: V) -> Result<(), ()> + fn serialize_struct(&mut self, name: &str, visitor: V) -> Result<(), ()> where V: ser::MapVisitor { let len = visitor.len(); @@ -277,7 +277,7 @@ impl<'a, I> ser::Serializer for Serializer self.visit_mapping(visitor) } - fn visit_struct_variant(&mut self, + fn serialize_struct_variant(&mut self, name: &str, _variant_index: usize, variant: &str, @@ -291,7 +291,7 @@ impl<'a, I> ser::Serializer for Serializer self.visit_mapping(visitor) } - fn visit_map_elt(&mut self, key: K, value: V) -> Result<(), ()> + fn serialize_map_elt(&mut self, key: K, value: V) -> Result<(), ()> where K: ser::Serialize, V: ser::Serialize, { @@ -376,7 +376,7 @@ impl de::Deserializer for Deserializer { type Error = Error; - fn visit(&mut self, mut visitor: V) -> Result + fn deserialize(&mut self, mut visitor: V) -> Result where V: de::Visitor, { println!("visit {:?}", self.tokens.peek()); @@ -416,7 +416,7 @@ impl de::Deserializer for Deserializer /// Hook into `Option` deserializing so we can treat `Unit` as a /// `None`, or a regular value as `Some(value)`. - fn visit_option(&mut self, mut visitor: V) -> Result + fn deserialize_option(&mut self, mut visitor: V) -> Result where V: de::Visitor, { match self.tokens.peek() { @@ -437,7 +437,7 @@ impl de::Deserializer for Deserializer } } - fn visit_enum(&mut self, + fn deserialize_enum(&mut self, name: &str, _variants: &'static [&'static str], mut visitor: V) -> Result @@ -467,7 +467,7 @@ impl de::Deserializer for Deserializer } } - fn visit_unit_struct(&mut self, name: &str, mut visitor: V) -> Result + fn deserialize_unit_struct(&mut self, name: &str, mut visitor: V) -> Result where V: de::Visitor, { match self.tokens.peek() { @@ -479,12 +479,12 @@ impl de::Deserializer for Deserializer Err(Error::InvalidName(n)) } } - Some(_) => self.visit(visitor), + Some(_) => self.deserialize(visitor), None => Err(Error::EndOfStreamError), } } - fn visit_newtype_struct(&mut self, + fn deserialize_newtype_struct(&mut self, name: &str, mut visitor: V) -> Result where V: de::Visitor, @@ -498,12 +498,12 @@ impl de::Deserializer for Deserializer Err(Error::InvalidName(n)) } } - Some(_) => self.visit(visitor), + Some(_) => self.deserialize(visitor), None => Err(Error::EndOfStreamError), } } - fn visit_tuple_struct(&mut self, + fn deserialize_tuple_struct(&mut self, name: &str, len: usize, mut visitor: V) -> Result @@ -530,12 +530,12 @@ impl de::Deserializer for Deserializer self.tokens.next(); self.visit_seq(Some(len), visitor) } - Some(_) => self.visit(visitor), + Some(_) => self.deserialize(visitor), None => Err(Error::EndOfStreamError), } } - fn visit_struct(&mut self, + fn deserialize_struct(&mut self, name: &str, fields: &'static [&'static str], visitor: V) -> Result @@ -554,7 +554,7 @@ impl de::Deserializer for Deserializer self.tokens.next(); self.visit_map(Some(fields.len()), visitor) } - Some(_) => self.visit(visitor), + Some(_) => self.deserialize(visitor), None => Err(Error::EndOfStreamError), } }