Compare commits

...

6 Commits

Author SHA1 Message Date
David Tolnay f12f640590 Release 0.8.0 2016-07-27 22:07:57 -07:00
David Tolnay d02e959b3f Merge pull request #468 from sfackler/split-map
Split serialize_map_elt
2016-07-27 12:50:42 -07:00
Steven Fackler ea833d3427 Split serialize_map_elt
Like what's been done on the deserialization side with MapVisitor, this
allows some weirder uses of Serde to handle the key and value in
separate steps.
2016-07-27 12:12:07 -07:00
David Tolnay 78e74886be Update syntex to 0.39 2016-07-26 09:22:33 -07:00
Oliver Schneider 061a1d8a8c Merge pull request #465 from serde-rs/underscore
Remove underscore from parameter names in deserializer traits
2016-07-26 08:25:15 +02:00
David Tolnay de9fd3b04e Remove underscore from parameter names in deserializer traits
This makes the generated rustdoc easier to read.
2016-07-25 20:18:45 -07:00
11 changed files with 83 additions and 64 deletions
+1 -3
View File
@@ -1,8 +1,6 @@
[package]
name = "serde"
# DO NOT RELEASE ANY MORE 0.7 RELEASES FROM THIS BRANCH
# USE THE 0.7.x BRANCH
version = "0.8.0-rc3"
version = "0.8.0"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "A generic serialization/deserialization framework"
+36 -25
View File
@@ -400,8 +400,8 @@ pub trait Deserializer {
/// This method hints that the `Deserialize` type is expecting a fixed size array. This allows
/// deserializers to parse arrays that aren't tagged as arrays.
fn deserialize_seq_fixed_size<V>(&mut self,
_len: usize,
visitor: V) -> Result<V::Value, Self::Error>
len: usize,
visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor;
/// This method hints that the `Deserialize` type is expecting a `Vec<u8>`. This allows
@@ -418,7 +418,7 @@ pub trait Deserializer {
/// This method hints that the `Deserialize` type is expecting a unit struct. This allows
/// deserializers to a unit struct that aren't tagged as a unit struct.
fn deserialize_unit_struct<V>(&mut self,
_name: &'static str,
name: &'static str,
visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor;
@@ -433,7 +433,7 @@ pub trait Deserializer {
/// This method hints that the `Deserialize` type is expecting a tuple struct. This allows
/// deserializers to parse sequences that aren't tagged as sequences.
fn deserialize_tuple_struct<V>(&mut self,
_name: &'static str,
name: &'static str,
len: usize,
visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor;
@@ -441,8 +441,8 @@ pub trait Deserializer {
/// This method hints that the `Deserialize` type is expecting a struct. This allows
/// deserializers to parse sequences that aren't tagged as maps.
fn deserialize_struct<V>(&mut self,
_name: &'static str,
_fields: &'static [&'static str],
name: &'static str,
fields: &'static [&'static str],
visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor;
@@ -454,16 +454,16 @@ pub trait Deserializer {
/// This method hints that the `Deserialize` type is expecting a tuple value. This allows
/// deserializers that provide a custom tuple serialization to properly deserialize the type.
fn deserialize_tuple<V>(&mut self, _len: usize, visitor: V) -> Result<V::Value, Self::Error>
fn deserialize_tuple<V>(&mut self, len: usize, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor;
/// This method hints that the `Deserialize` type is expecting an enum value. This allows
/// deserializers that provide a custom enumeration serialization to properly deserialize the
/// type.
fn deserialize_enum<V>(&mut self,
_enum: &'static str,
_variants: &'static [&'static str],
_visitor: V) -> Result<V::Value, Self::Error>
name: &'static str,
variants: &'static [&'static str],
visitor: V) -> Result<V::Value, Self::Error>
where V: EnumVisitor;
/// This method hints that the `Deserialize` type needs to deserialize a value whose type
@@ -480,9 +480,10 @@ pub trait Visitor {
type Value: Deserialize;
/// `visit_bool` deserializes a `bool` into a `Value`.
fn visit_bool<E>(&mut self, _v: bool) -> Result<Self::Value, E>
fn visit_bool<E>(&mut self, v: bool) -> Result<Self::Value, E>
where E: Error,
{
let _ = v;
Err(Error::invalid_type(Type::Bool))
}
@@ -515,9 +516,10 @@ pub trait Visitor {
}
/// `visit_i64` deserializes a `i64` into a `Value`.
fn visit_i64<E>(&mut self, _v: i64) -> Result<Self::Value, E>
fn visit_i64<E>(&mut self, v: i64) -> Result<Self::Value, E>
where E: Error,
{
let _ = v;
Err(Error::invalid_type(Type::I64))
}
@@ -550,9 +552,10 @@ pub trait Visitor {
}
/// `visit_u64` deserializes a `u64` into a `Value`.
fn visit_u64<E>(&mut self, _v: u64) -> Result<Self::Value, E>
fn visit_u64<E>(&mut self, v: u64) -> Result<Self::Value, E>
where E: Error,
{
let _ = v;
Err(Error::invalid_type(Type::U64))
}
@@ -564,9 +567,10 @@ pub trait Visitor {
}
/// `visit_f64` deserializes a `f64` into a `Value`.
fn visit_f64<E>(&mut self, _v: f64) -> Result<Self::Value, E>
fn visit_f64<E>(&mut self, v: f64) -> Result<Self::Value, E>
where E: Error,
{
let _ = v;
Err(Error::invalid_type(Type::F64))
}
@@ -579,9 +583,10 @@ pub trait Visitor {
}
/// `visit_str` deserializes a `&str` into a `Value`.
fn visit_str<E>(&mut self, _v: &str) -> Result<Self::Value, E>
fn visit_str<E>(&mut self, v: &str) -> Result<Self::Value, E>
where E: Error,
{
let _ = v;
Err(Error::invalid_type(Type::Str))
}
@@ -605,9 +610,10 @@ pub trait Visitor {
/// `visit_unit_struct` deserializes a unit struct into a `Value`.
#[inline]
fn visit_unit_struct<E>(&mut self, _name: &'static str) -> Result<Self::Value, E>
fn visit_unit_struct<E>(&mut self, name: &'static str) -> Result<Self::Value, E>
where E: Error,
{
let _ = name;
self.visit_unit()
}
@@ -619,37 +625,42 @@ pub trait Visitor {
}
/// `visit_some` deserializes a value into a `Value`.
fn visit_some<D>(&mut self, _deserializer: &mut D) -> Result<Self::Value, D::Error>
fn visit_some<D>(&mut self, deserializer: &mut D) -> Result<Self::Value, D::Error>
where D: Deserializer,
{
let _ = deserializer;
Err(Error::invalid_type(Type::Option))
}
/// `visit_newtype_struct` deserializes a value into a `Value`.
fn visit_newtype_struct<D>(&mut self, _deserializer: &mut D) -> Result<Self::Value, D::Error>
fn visit_newtype_struct<D>(&mut self, deserializer: &mut D) -> Result<Self::Value, D::Error>
where D: Deserializer,
{
let _ = deserializer;
Err(Error::invalid_type(Type::NewtypeStruct))
}
/// `visit_seq` deserializes a `SeqVisitor` into a `Value`.
fn visit_seq<V>(&mut self, _visitor: V) -> Result<Self::Value, V::Error>
fn visit_seq<V>(&mut self, visitor: V) -> Result<Self::Value, V::Error>
where V: SeqVisitor,
{
let _ = visitor;
Err(Error::invalid_type(Type::Seq))
}
/// `visit_map` deserializes a `MapVisitor` into a `Value`.
fn visit_map<V>(&mut self, _visitor: V) -> Result<Self::Value, V::Error>
fn visit_map<V>(&mut self, visitor: V) -> Result<Self::Value, V::Error>
where V: MapVisitor,
{
let _ = visitor;
Err(Error::invalid_type(Type::Map))
}
/// `visit_bytes` deserializes a `&[u8]` into a `Value`.
fn visit_bytes<E>(&mut self, _v: &[u8]) -> Result<Self::Value, E>
fn visit_bytes<E>(&mut self, v: &[u8]) -> Result<Self::Value, E>
where E: Error,
{
let _ = v;
Err(Error::invalid_type(Type::Bytes))
}
@@ -834,16 +845,16 @@ pub trait VariantVisitor {
/// If no tuple variants are expected, yield a
/// `Err(serde::de::Error::invalid_type(serde::de::Type::TupleVariant))`
fn visit_tuple<V>(&mut self,
_len: usize,
_visitor: V) -> Result<V::Value, Self::Error>
len: usize,
visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor;
/// `visit_struct` is called when deserializing a struct-like variant.
/// If no struct variants are expected, yield a
/// `Err(serde::de::Error::invalid_type(serde::de::Type::StructVariant))`
fn visit_struct<V>(&mut self,
_fields: &'static [&'static str],
_visitor: V) -> Result<V::Value, Self::Error>
fields: &'static [&'static str],
visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor;
}
+2 -1
View File
@@ -522,7 +522,8 @@ macro_rules! serialize_map {
{
let mut state = try!(serializer.serialize_map(Some(self.len())));
for (k, v) in self {
try!(serializer.serialize_map_elt(&mut state, k, v));
try!(serializer.serialize_map_key(&mut state, k));
try!(serializer.serialize_map_value(&mut state, v));
}
serializer.serialize_map_end(state)
}
+12 -5
View File
@@ -334,18 +334,25 @@ pub trait Serializer {
) -> Result<(), Self::Error>;
/// Begins to serialize a map. This call must be followed by zero or more
/// calls to `serialize_map_elt`, then a call to `serialize_map_end`.
/// calls to `serialize_map_key` and `serialize_map_value`, then a call to
/// `serialize_map_end`.
fn serialize_map(
&mut self,
len: Option<usize>,
) -> Result<Self::MapState, Self::Error>;
/// Serialize a map element. Must have previously called `serialize_map`.
fn serialize_map_elt<K: Serialize, V: Serialize>(
/// Serialize a map key. Must have previously called `serialize_map`.
fn serialize_map_key<T: Serialize>(
&mut self,
state: &mut Self::MapState,
key: K,
value: V,
key: T
) -> Result<(), Self::Error>;
/// Serialize a map value. Must have previously called `serialize_map`.
fn serialize_map_value<T: Serialize>(
&mut self,
state: &mut Self::MapState,
value: T
) -> Result<(), Self::Error>;
/// Finishes serializing a map.
+9 -11
View File
@@ -1,8 +1,6 @@
[package]
name = "serde_codegen"
# DO NOT RELEASE ANY MORE 0.7 RELEASES FROM THIS BRANCH
# USE THE 0.7.x BRANCH
version = "0.8.0-rc3"
version = "0.8.0"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Macros to auto-generate implementations for the serde framework"
@@ -26,14 +24,14 @@ with-syntex = [
]
[build-dependencies]
quasi_codegen = { version = "^0.15.0", optional = true }
syntex = { version = "^0.38.0", optional = true }
quasi_codegen = { version = "^0.16.0", optional = true }
syntex = { version = "^0.39.0", optional = true }
[dependencies]
aster = { version = "^0.21.1", default-features = false }
aster = { version = "^0.22.0", default-features = false }
clippy = { version = "^0.*", optional = true }
quasi = { version = "^0.15.0", default-features = false }
quasi_macros = { version = "^0.15.0", optional = true }
serde_codegen_internals = { version = "0.4.0-rc1", default-features = false }
syntex = { version = "^0.38.0", optional = true }
syntex_syntax = { version = "^0.38.0", optional = true }
quasi = { version = "^0.16.0", default-features = false }
quasi_macros = { version = "^0.16.0", optional = true }
serde_codegen_internals = { version = "0.5.0", default-features = false }
syntex = { version = "^0.39.0", optional = true }
syntex_syntax = { version = "^0.39.0", optional = true }
+3 -3
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_codegen_internals"
version = "0.4.0-rc1"
version = "0.5.0"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "AST representation used by Serde codegen. Unstable."
@@ -16,5 +16,5 @@ with-syntex = ["syntex_syntax", "syntex_errors"]
[dependencies]
clippy = { version = "^0.*", optional = true }
syntex_syntax = { version = "^0.38.0", optional = true }
syntex_errors = { version = "^0.38.0", optional = true }
syntex_syntax = { version = "^0.39.0", optional = true }
syntex_errors = { version = "^0.39.0", optional = true }
+4 -6
View File
@@ -1,8 +1,6 @@
[package]
name = "serde_macros"
# DO NOT RELEASE ANY MORE 0.7 RELEASES FROM THIS BRANCH
# USE THE 0.7.x BRANCH
version = "0.8.0-rc3"
version = "0.8.0"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Macros to auto-generate implementations for the serde framework"
@@ -20,15 +18,15 @@ unstable-testing = ["clippy", "serde/unstable-testing", "serde_codegen/unstable-
[dependencies]
clippy = { version = "^0.*", optional = true }
serde_codegen = { version = "^0.8.0-rc3", default-features = false, features = ["unstable"] }
serde_codegen = { version = "0.8.0", default-features = false, features = ["unstable"] }
[dev-dependencies]
clippy = "^0.*"
compiletest_rs = "^0.2.0"
fnv = "1.0"
rustc-serialize = "^0.3.16"
serde = "0.8.0-rc3"
serde_test = "0.8.0-rc3"
serde = "0.8.0"
serde_test = "0.8.0"
[[test]]
name = "test"
+2 -4
View File
@@ -1,8 +1,6 @@
[package]
name = "serde_test"
# DO NOT RELEASE ANY MORE 0.7 RELEASES FROM THIS BRANCH
# USE THE 0.7.x BRANCH
version = "0.8.0-rc3"
version = "0.8.0"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "Token De/Serializer for testing De/Serialize implementations"
@@ -13,4 +11,4 @@ keywords = ["serde", "serialization"]
include = ["Cargo.toml", "src/**/*.rs"]
[dependencies]
serde = "0.8.0-rc3"
serde = "0.8.0"
+5 -2
View File
@@ -259,9 +259,12 @@ impl<'a, I> ser::Serializer for Serializer<'a, I>
Ok(())
}
fn serialize_map_elt<K, V>(&mut self, _: &mut (), key: K, value: V) -> Result<(), Self::Error> where K: Serialize, V: Serialize {
fn serialize_map_key<T>(&mut self, _: &mut (), key: T) -> Result<(), Self::Error> where T: Serialize {
assert_eq!(self.tokens.next(), Some(&Token::MapSep));
try!(key.serialize(self));
key.serialize(self)
}
fn serialize_map_value<T>(&mut self, _: &mut (), value: T) -> Result<(), Self::Error> where T: Serialize {
value.serialize(self)
}
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "serde_testing"
version = "0.8.0-rc3"
version = "0.8.0"
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
license = "MIT/Apache-2.0"
description = "A generic serialization/deserialization framework"
+8 -3
View File
@@ -229,9 +229,14 @@ impl Serializer for BytesSerializer {
Err(Error)
}
fn serialize_map_elt<K, V>(&mut self, _: &mut (), _key: K, _value: V) -> Result<(), Error>
where K: Serialize,
V: Serialize,
fn serialize_map_key<T>(&mut self, _: &mut (), _key: T) -> Result<(), Error>
where T: Serialize
{
Err(Error)
}
fn serialize_map_value<T>(&mut self, _: &mut (), _value: T) -> Result<(), Error>
where T: Serialize
{
Err(Error)
}