From 7ace67e997982e522d3edbf92afc724105a14ec7 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Tue, 26 Jan 2016 19:34:33 -0800 Subject: [PATCH 1/2] docs(readme) fix method calls on de/serializers Several instances of serializer and deserializer had methods like visit_* being invoked on them when the intent was to invoke de/serialize_*. --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2db17d44..9ecab2a6 100644 --- a/README.md +++ b/README.md @@ -256,7 +256,7 @@ impl serde::Serialize for i32 { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: serde::Serializer, { - serializer.visit_i32(*self) + serializer.serialize_i32(*self) } } ``` @@ -277,7 +277,7 @@ impl Serialize for BTreeMap fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer, { - serializer.visit_map(MapIteratorVisitor::new(self.iter(), Some(self.len()))) + serializer.serialize_map(MapIteratorVisitor::new(self.iter(), Some(self.len()))) } } @@ -309,7 +309,7 @@ impl MapVisitor for MapIteratorVisitor { match self.iter.next() { Some((key, value)) => { - let value = try!(serializer.visit_map_elt(key, value)); + let value = try!(serializer.serialize_map_elt(key, value)); Ok(Some(value)) } None => Ok(None) @@ -339,7 +339,7 @@ impl serde::Serialize for Point { fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: serde::Serializer { - serializer.visit_struct("Point", PointMapVisitor { + serializer.serialize_struct("Point", PointMapVisitor { value: self, state: 0, }) @@ -358,11 +358,11 @@ impl<'a> serde::ser::MapVisitor for PointMapVisitor<'a> { match self.state { 0 => { self.state += 1; - Ok(Some(try!(serializer.visit_struct_elt("x", &self.value.x)))) + Ok(Some(try!(serializer.serialize_struct_elt("x", &self.value.x)))) } 1 => { self.state += 1; - Ok(Some(try!(serializer.visit_struct_elt("y", &self.value.y)))) + Ok(Some(try!(serializer.serialize_struct_elt("y", &self.value.y)))) } _ => { Ok(None) @@ -389,7 +389,7 @@ impl Deserialize for i32 { fn deserialize(deserializer: &mut D) -> Result where D: serde::Deserializer, { - deserializer.visit(I32Visitor) + deserializer.deserialize(I32Visitor) } } @@ -447,7 +447,7 @@ impl serde::Deserialize for BTreeMap fn deserialize(deserializer: &mut D) -> Result, D::Error> where D: serde::Deserializer, { - deserializer.visit(BTreeMapVisitor::new()) + deserializer.deserialize(BTreeMapVisitor::new()) } } @@ -530,7 +530,7 @@ impl serde::Deserialize for PointField { } } - deserializer.visit(PointFieldVisitor) + deserializer.deserialize(PointFieldVisitor) } } @@ -539,7 +539,7 @@ impl serde::Deserialize for Point { where D: serde::de::Deserializer { static FIELDS: &'static [&'static str] = &["x", "y"]; - deserializer.visit_struct("Point", FIELDS, PointVisitor) + deserializer.deserialize_struct("Point", FIELDS, PointVisitor) } } From 1b6ae02e8ac3424819eac6bb1da745e3d7414c24 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Tue, 26 Jan 2016 20:18:49 -0800 Subject: [PATCH 2/2] docs(readme) update links for documentation Documentation links were all broken. --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 9ecab2a6..90c266ca 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ the same speed as a hand written serializer for a specific type. Documentation is available at: -* [serde](https://serde-rs.github.io/serde/serde/serde/index.html) -* [serde\_json](https://serde-rs.github.io/serde/serde_json/serde_json/index.html) -* [serde\_codegen](https://serde-rs.github.io/serde/serde_codegen/serde_codegen/index.html) +* [serde](https://serde-rs.github.io/serde/serde/serde/serde/index.html) +* [serde\_json](https://serde-rs.github.io/serde/serde/serde_json/serde_json/index.html) +* [serde\_codegen](https://serde-rs.github.io/serde/serde/serde_codegen/serde_codegen/index.html) Using Serde with Nightly Rust and serde\_macros =============================================== @@ -237,9 +237,9 @@ Serialization without Macros Under the covers, Serde extensively uses the Visitor pattern to thread state between the -[Serializer](http://serde-rs.github.io/serde/serde/ser/trait.Serializer.html) +[Serializer](http://serde-rs.github.io/serde/serde/serde/ser/trait.Serializer.html) and -[Serialize](http://serde-rs.github.io/serde/serde/ser/trait.Serialize.html) +[Serialize](http://serde-rs.github.io/serde/serde/serde/ser/trait.Serialize.html) without the two having specific information about each other's concrete type. This has many of the same benefits as frameworks that use runtime type information without the overhead. In fact, when compiling with optimizations, @@ -248,7 +248,7 @@ nearly as fast as a hand written serializer format for a specific type. To see it in action, lets look at how a simple type like `i32` is serialized. The -[Serializer](http://serde-rs.github.io/serde/serde/ser/trait.Serializer.html) +[Serializer](http://serde-rs.github.io/serde/serde/serde/ser/trait.Serializer.html) is threaded through the type: ```rust @@ -263,9 +263,9 @@ impl serde::Serialize for i32 { As you can see it's pretty simple. More complex types like `BTreeMap` need to pass a -[MapVisitor](http://serde-rs.github.io/serde/serde/ser/trait.MapVisitor.html) +[MapVisitor](http://serde-rs.github.io/serde/serde/serde/ser/trait.MapVisitor.html) to the -[Serializer](http://serde-rs.github.io/serde/serde/ser/trait.Serializer.html) +[Serializer](http://serde-rs.github.io/serde/serde/serde/ser/trait.Serializer.html) in order to walk through the type: ```rust @@ -377,11 +377,11 @@ Deserialization without Macros Deserialization is a little more complicated since there's a bit more error handling that needs to occur. Let's start with the simple `i32` -[Deserialize](http://serde-rs.github.io/serde/serde/de/trait.Deserialize.html) +[Deserialize](http://serde-rs.github.io/serde/serde/serde/de/trait.Deserialize.html) implementation. It passes a -[Visitor](http://serde-rs.github.io/serde/serde/de/trait.Visitor.html) to the -[Deserializer](http://serde-rs.github.io/serde/serde/de/trait.Deserializer.html). -The [Visitor](http://serde-rs.github.io/serde/serde/de/trait.Visitor.html) +[Visitor](http://serde-rs.github.io/serde/serde/serde/de/trait.Visitor.html) to the +[Deserializer](http://serde-rs.github.io/serde/serde/serde/de/trait.Deserializer.html). +The [Visitor](http://serde-rs.github.io/serde/serde/serde/de/trait.Visitor.html) can create the `i32` from a variety of different types: ```rust @@ -416,9 +416,9 @@ impl serde::de::Visitor for I32Visitor { Since it's possible for this type to get passed an unexpected type, we need a way to error out. This is done by way of the -[Error](http://serde-rs.github.io/serde/serde/de/trait.Error.html) trait, +[Error](http://serde-rs.github.io/serde/serde/serde/de/trait.Error.html) trait, which allows a -[Deserialize](http://serde-rs.github.io/serde/serde/de/trait.Deserialize.html) +[Deserialize](http://serde-rs.github.io/serde/serde/serde/de/trait.Deserialize.html) to generate an error for a few common error conditions. Here's how it could be used: ```rust @@ -435,9 +435,9 @@ to generate an error for a few common error conditions. Here's how it could be u ``` Maps follow a similar pattern as before, and use a -[MapVisitor](http://serde-rs.github.io/serde/serde/de/trait.MapVisitor.html) +[MapVisitor](http://serde-rs.github.io/serde/serde/serde/de/trait.MapVisitor.html) to walk through the values generated by the -[Deserializer](http://serde-rs.github.io/serde/serde/de/trait.Deserializer.html). +[Deserializer](http://serde-rs.github.io/serde/serde/serde/de/trait.Deserializer.html). ```rust impl serde::Deserialize for BTreeMap