mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-14 09:21:01 +00:00
Merge pull request #298 from dtolnay/scope
fix(codegen): Support `extern crate serde` not in toplevel module
This commit is contained in:
@@ -46,7 +46,6 @@ serde_macros = "*"
|
|||||||
#![feature(custom_derive, plugin)]
|
#![feature(custom_derive, plugin)]
|
||||||
#![plugin(serde_macros)]
|
#![plugin(serde_macros)]
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|||||||
@@ -572,14 +572,14 @@ fn wrap_serialize_with(cx: &ExtCtxt,
|
|||||||
quote_expr!(cx, {
|
quote_expr!(cx, {
|
||||||
trait __SerdeSerializeWith {
|
trait __SerdeSerializeWith {
|
||||||
fn __serde_serialize_with<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
fn __serde_serialize_with<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||||
where S: ::serde::ser::Serializer;
|
where S: _serde::ser::Serializer;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> __SerdeSerializeWith for &'a T
|
impl<'a, T> __SerdeSerializeWith for &'a T
|
||||||
where T: 'a + __SerdeSerializeWith,
|
where T: 'a + __SerdeSerializeWith,
|
||||||
{
|
{
|
||||||
fn __serde_serialize_with<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
fn __serde_serialize_with<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||||
where S: ::serde::ser::Serializer
|
where S: _serde::ser::Serializer
|
||||||
{
|
{
|
||||||
(**self).__serde_serialize_with(serializer)
|
(**self).__serde_serialize_with(serializer)
|
||||||
}
|
}
|
||||||
@@ -587,7 +587,7 @@ fn wrap_serialize_with(cx: &ExtCtxt,
|
|||||||
|
|
||||||
impl $generics __SerdeSerializeWith for $container_ty $where_clause {
|
impl $generics __SerdeSerializeWith for $container_ty $where_clause {
|
||||||
fn __serde_serialize_with<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
fn __serde_serialize_with<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||||
where S: ::serde::ser::Serializer
|
where S: _serde::ser::Serializer
|
||||||
{
|
{
|
||||||
$expr
|
$expr
|
||||||
}
|
}
|
||||||
@@ -597,11 +597,11 @@ fn wrap_serialize_with(cx: &ExtCtxt,
|
|||||||
value: &'a T,
|
value: &'a T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> ::serde::ser::Serialize for __SerdeSerializeWithStruct<'a, T>
|
impl<'a, T> _serde::ser::Serialize for __SerdeSerializeWithStruct<'a, T>
|
||||||
where T: 'a + __SerdeSerializeWith
|
where T: 'a + __SerdeSerializeWith
|
||||||
{
|
{
|
||||||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
|
||||||
where S: ::serde::ser::Serializer
|
where S: _serde::ser::Serializer
|
||||||
{
|
{
|
||||||
self.value.__serde_serialize_with(serializer)
|
self.value.__serde_serialize_with(serializer)
|
||||||
}
|
}
|
||||||
@@ -633,9 +633,9 @@ fn wrap_deserialize_with(cx: &ExtCtxt,
|
|||||||
value: $field_ty,
|
value: $field_ty,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $generics ::serde::de::Deserialize for $ty_path $where_clause {
|
impl $generics _serde::de::Deserialize for $ty_path $where_clause {
|
||||||
fn deserialize<D>(deserializer: &mut D) -> ::std::result::Result<Self, D::Error>
|
fn deserialize<D>(deserializer: &mut D) -> ::std::result::Result<Self, D::Error>
|
||||||
where D: ::serde::de::Deserializer
|
where D: _serde::de::Deserializer
|
||||||
{
|
{
|
||||||
let value = try!($path(deserializer));
|
let value = try!($path(deserializer));
|
||||||
Ok(__SerdeDeserializeWithStruct { value: value })
|
Ok(__SerdeDeserializeWithStruct { value: value })
|
||||||
|
|||||||
@@ -27,10 +27,8 @@ pub fn with_bound(
|
|||||||
item: &ast::Item,
|
item: &ast::Item,
|
||||||
generics: &ast::Generics,
|
generics: &ast::Generics,
|
||||||
filter: &Fn(&ast::StructField) -> bool,
|
filter: &Fn(&ast::StructField) -> bool,
|
||||||
bound: &[&'static str],
|
bound: &ast::Path,
|
||||||
) -> ast::Generics {
|
) -> ast::Generics {
|
||||||
let path = builder.path().global().ids(bound).build();
|
|
||||||
|
|
||||||
builder.from_generics(generics.clone())
|
builder.from_generics(generics.clone())
|
||||||
.with_predicates(
|
.with_predicates(
|
||||||
all_variants(cx, item).iter()
|
all_variants(cx, item).iter()
|
||||||
@@ -44,7 +42,7 @@ pub fn with_bound(
|
|||||||
// the type that is being bounded e.g. T
|
// the type that is being bounded e.g. T
|
||||||
.bound().build(ty.clone())
|
.bound().build(ty.clone())
|
||||||
// the bound e.g. Serialize
|
// the bound e.g. Serialize
|
||||||
.bound().trait_(path.clone()).build()
|
.bound().trait_(bound.clone()).build()
|
||||||
.build()))
|
.build()))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-44
@@ -63,14 +63,21 @@ pub fn expand_derive_deserialize(
|
|||||||
|
|
||||||
let where_clause = &impl_generics.where_clause;
|
let where_clause = &impl_generics.where_clause;
|
||||||
|
|
||||||
|
let dummy_const = builder.id(format!("_IMPL_DESERIALIZE_FOR_{}", item.ident));
|
||||||
|
|
||||||
let impl_item = quote_item!(cx,
|
let impl_item = quote_item!(cx,
|
||||||
impl $impl_generics ::serde::de::Deserialize for $ty $where_clause {
|
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||||
fn deserialize<__D>(deserializer: &mut __D) -> ::std::result::Result<$ty, __D::Error>
|
const $dummy_const: () = {
|
||||||
where __D: ::serde::de::Deserializer,
|
extern crate serde as _serde;
|
||||||
{
|
#[automatically_derived]
|
||||||
$body
|
impl $impl_generics _serde::de::Deserialize for $ty $where_clause {
|
||||||
|
fn deserialize<__D>(deserializer: &mut __D) -> ::std::result::Result<$ty, __D::Error>
|
||||||
|
where __D: _serde::de::Deserializer,
|
||||||
|
{
|
||||||
|
$body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
push(Annotatable::Item(impl_item))
|
push(Annotatable::Item(impl_item))
|
||||||
@@ -88,10 +95,10 @@ fn build_impl_generics(
|
|||||||
let generics = bound::without_defaults(generics);
|
let generics = bound::without_defaults(generics);
|
||||||
let generics = bound::with_bound(cx, builder, item, &generics,
|
let generics = bound::with_bound(cx, builder, item, &generics,
|
||||||
&deserialized_by_us,
|
&deserialized_by_us,
|
||||||
&["serde", "de", "Deserialize"]);
|
&builder.path().ids(&["_serde", "de", "Deserialize"]).build());
|
||||||
let generics = bound::with_bound(cx, builder, item, &generics,
|
let generics = bound::with_bound(cx, builder, item, &generics,
|
||||||
&requires_default,
|
&requires_default,
|
||||||
&["std", "default", "Default"]);
|
&builder.path().global().ids(&["std", "default", "Default"]).build());
|
||||||
generics
|
generics
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,8 +330,7 @@ fn deserialize_visitor(
|
|||||||
fn deserializer_ty_param(builder: &aster::AstBuilder) -> ast::TyParam {
|
fn deserializer_ty_param(builder: &aster::AstBuilder) -> ast::TyParam {
|
||||||
builder.ty_param("__D")
|
builder.ty_param("__D")
|
||||||
.trait_bound(builder.path()
|
.trait_bound(builder.path()
|
||||||
.global()
|
.segment("_serde").build()
|
||||||
.segment("serde").build()
|
|
||||||
.segment("de").build()
|
.segment("de").build()
|
||||||
.id("Deserializer")
|
.id("Deserializer")
|
||||||
.build())
|
.build())
|
||||||
@@ -346,19 +352,19 @@ fn deserialize_unit_struct(
|
|||||||
Ok(quote_expr!(cx, {
|
Ok(quote_expr!(cx, {
|
||||||
struct __Visitor;
|
struct __Visitor;
|
||||||
|
|
||||||
impl ::serde::de::Visitor for __Visitor {
|
impl _serde::de::Visitor for __Visitor {
|
||||||
type Value = $type_ident;
|
type Value = $type_ident;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_unit<E>(&mut self) -> ::std::result::Result<$type_ident, E>
|
fn visit_unit<E>(&mut self) -> ::std::result::Result<$type_ident, E>
|
||||||
where E: ::serde::de::Error,
|
where E: _serde::de::Error,
|
||||||
{
|
{
|
||||||
Ok($type_ident)
|
Ok($type_ident)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_seq<V>(&mut self, mut visitor: V) -> ::std::result::Result<$type_ident, V::Error>
|
fn visit_seq<V>(&mut self, mut visitor: V) -> ::std::result::Result<$type_ident, V::Error>
|
||||||
where V: ::serde::de::SeqVisitor,
|
where V: _serde::de::SeqVisitor,
|
||||||
{
|
{
|
||||||
try!(visitor.end());
|
try!(visitor.end());
|
||||||
self.visit_unit()
|
self.visit_unit()
|
||||||
@@ -398,20 +404,20 @@ fn deserialize_newtype_struct(
|
|||||||
Ok(quote_expr!(cx, {
|
Ok(quote_expr!(cx, {
|
||||||
$visitor_item
|
$visitor_item
|
||||||
|
|
||||||
impl $visitor_generics ::serde::de::Visitor for $visitor_ty $where_clause {
|
impl $visitor_generics _serde::de::Visitor for $visitor_ty $where_clause {
|
||||||
type Value = $ty;
|
type Value = $ty;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_newtype_struct<D>(&mut self, deserializer: &mut D) -> ::std::result::Result<Self::Value, D::Error>
|
fn visit_newtype_struct<D>(&mut self, deserializer: &mut D) -> ::std::result::Result<Self::Value, D::Error>
|
||||||
where D: ::serde::de::Deserializer,
|
where D: _serde::de::Deserializer,
|
||||||
{
|
{
|
||||||
let value = try!(::serde::de::Deserialize::deserialize(deserializer));
|
let value = try!(_serde::de::Deserialize::deserialize(deserializer));
|
||||||
Ok($type_ident(value))
|
Ok($type_ident(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||||
where __V: ::serde::de::SeqVisitor,
|
where __V: _serde::de::SeqVisitor,
|
||||||
{
|
{
|
||||||
$visit_seq_expr
|
$visit_seq_expr
|
||||||
}
|
}
|
||||||
@@ -451,12 +457,12 @@ fn deserialize_tuple_struct(
|
|||||||
Ok(quote_expr!(cx, {
|
Ok(quote_expr!(cx, {
|
||||||
$visitor_item
|
$visitor_item
|
||||||
|
|
||||||
impl $visitor_generics ::serde::de::Visitor for $visitor_ty $where_clause {
|
impl $visitor_generics _serde::de::Visitor for $visitor_ty $where_clause {
|
||||||
type Value = $ty;
|
type Value = $ty;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||||
where __V: ::serde::de::SeqVisitor,
|
where __V: _serde::de::SeqVisitor,
|
||||||
{
|
{
|
||||||
$visit_seq_expr
|
$visit_seq_expr
|
||||||
}
|
}
|
||||||
@@ -479,7 +485,7 @@ fn deserialize_seq(
|
|||||||
let $name = match try!(visitor.visit()) {
|
let $name = match try!(visitor.visit()) {
|
||||||
Some(value) => { value },
|
Some(value) => { value },
|
||||||
None => {
|
None => {
|
||||||
return Err(::serde::de::Error::end_of_stream());
|
return Err(_serde::de::Error::end_of_stream());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
).unwrap()
|
).unwrap()
|
||||||
@@ -521,7 +527,7 @@ fn deserialize_struct_as_seq(
|
|||||||
let $name = match try!(visitor.visit()) {
|
let $name = match try!(visitor.visit()) {
|
||||||
Some(value) => { $deserialize_with(value) },
|
Some(value) => { $deserialize_with(value) },
|
||||||
None => {
|
None => {
|
||||||
return Err(::serde::de::Error::end_of_stream());
|
return Err(_serde::de::Error::end_of_stream());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
).unwrap()
|
).unwrap()
|
||||||
@@ -600,19 +606,19 @@ fn deserialize_struct(
|
|||||||
|
|
||||||
$visitor_item
|
$visitor_item
|
||||||
|
|
||||||
impl $visitor_generics ::serde::de::Visitor for $visitor_ty $where_clause {
|
impl $visitor_generics _serde::de::Visitor for $visitor_ty $where_clause {
|
||||||
type Value = $ty;
|
type Value = $ty;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||||
where __V: ::serde::de::SeqVisitor,
|
where __V: _serde::de::SeqVisitor,
|
||||||
{
|
{
|
||||||
$visit_seq_expr
|
$visit_seq_expr
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_map<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
fn visit_map<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||||
where __V: ::serde::de::MapVisitor,
|
where __V: _serde::de::MapVisitor,
|
||||||
{
|
{
|
||||||
$visit_map_expr
|
$visit_map_expr
|
||||||
}
|
}
|
||||||
@@ -668,7 +674,7 @@ fn deserialize_item_enum(
|
|||||||
let ignored_arm = if container_attrs.deny_unknown_fields() {
|
let ignored_arm = if container_attrs.deny_unknown_fields() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(quote_arm!(cx, __Field::__ignore => { Err(::serde::de::Error::end_of_stream()) }))
|
Some(quote_arm!(cx, __Field::__ignore => { Err(_serde::de::Error::end_of_stream()) }))
|
||||||
};
|
};
|
||||||
|
|
||||||
// Match arms to extract a variant from a string
|
// Match arms to extract a variant from a string
|
||||||
@@ -705,11 +711,11 @@ fn deserialize_item_enum(
|
|||||||
|
|
||||||
$visitor_item
|
$visitor_item
|
||||||
|
|
||||||
impl $visitor_generics ::serde::de::EnumVisitor for $visitor_ty $where_clause {
|
impl $visitor_generics _serde::de::EnumVisitor for $visitor_ty $where_clause {
|
||||||
type Value = $ty;
|
type Value = $ty;
|
||||||
|
|
||||||
fn visit<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
fn visit<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||||
where __V: ::serde::de::VariantVisitor,
|
where __V: _serde::de::VariantVisitor,
|
||||||
{
|
{
|
||||||
match try!(visitor.visit_variant()) {
|
match try!(visitor.visit_variant()) {
|
||||||
$variant_arms
|
$variant_arms
|
||||||
@@ -801,11 +807,11 @@ fn deserialize_tuple_variant(
|
|||||||
Ok(quote_expr!(cx, {
|
Ok(quote_expr!(cx, {
|
||||||
$visitor_item
|
$visitor_item
|
||||||
|
|
||||||
impl $visitor_generics ::serde::de::Visitor for $visitor_ty $where_clause {
|
impl $visitor_generics _serde::de::Visitor for $visitor_ty $where_clause {
|
||||||
type Value = $ty;
|
type Value = $ty;
|
||||||
|
|
||||||
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||||
where __V: ::serde::de::SeqVisitor,
|
where __V: _serde::de::SeqVisitor,
|
||||||
{
|
{
|
||||||
$visit_seq_expr
|
$visit_seq_expr
|
||||||
}
|
}
|
||||||
@@ -861,19 +867,19 @@ fn deserialize_struct_variant(
|
|||||||
|
|
||||||
$visitor_item
|
$visitor_item
|
||||||
|
|
||||||
impl $visitor_generics ::serde::de::Visitor for $visitor_ty $where_clause {
|
impl $visitor_generics _serde::de::Visitor for $visitor_ty $where_clause {
|
||||||
type Value = $ty;
|
type Value = $ty;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||||
where __V: ::serde::de::SeqVisitor,
|
where __V: _serde::de::SeqVisitor,
|
||||||
{
|
{
|
||||||
$visit_seq_expr
|
$visit_seq_expr
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_map<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
fn visit_map<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||||
where __V: ::serde::de::MapVisitor,
|
where __V: _serde::de::MapVisitor,
|
||||||
{
|
{
|
||||||
$field_expr
|
$field_expr
|
||||||
}
|
}
|
||||||
@@ -932,7 +938,7 @@ fn deserialize_field_visitor(
|
|||||||
quote_expr!(cx, Ok(__Field::__ignore))
|
quote_expr!(cx, Ok(__Field::__ignore))
|
||||||
} else {
|
} else {
|
||||||
quote_expr!(cx, {
|
quote_expr!(cx, {
|
||||||
Err(::serde::de::Error::invalid_value($index_error_msg))
|
Err(_serde::de::Error::invalid_value($index_error_msg))
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -958,7 +964,7 @@ fn deserialize_field_visitor(
|
|||||||
let fallthrough_str_arm_expr = if !is_variant && !container_attrs.deny_unknown_fields() {
|
let fallthrough_str_arm_expr = if !is_variant && !container_attrs.deny_unknown_fields() {
|
||||||
quote_expr!(cx, Ok(__Field::__ignore))
|
quote_expr!(cx, Ok(__Field::__ignore))
|
||||||
} else {
|
} else {
|
||||||
quote_expr!(cx, Err(::serde::de::Error::$unknown_ident(value)))
|
quote_expr!(cx, Err(_serde::de::Error::$unknown_ident(value)))
|
||||||
};
|
};
|
||||||
|
|
||||||
let str_body = quote_expr!(cx,
|
let str_body = quote_expr!(cx,
|
||||||
@@ -988,7 +994,7 @@ fn deserialize_field_visitor(
|
|||||||
} else {
|
} else {
|
||||||
quote_expr!(cx, {
|
quote_expr!(cx, {
|
||||||
let value = ::std::string::String::from_utf8_lossy(value);
|
let value = ::std::string::String::from_utf8_lossy(value);
|
||||||
Err(::serde::de::Error::$unknown_ident(&value))
|
Err(_serde::de::Error::$unknown_ident(&value))
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1000,10 +1006,10 @@ fn deserialize_field_visitor(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let impl_item = quote_item!(cx,
|
let impl_item = quote_item!(cx,
|
||||||
impl ::serde::de::Deserialize for __Field {
|
impl _serde::de::Deserialize for __Field {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn deserialize<D>(deserializer: &mut D) -> ::std::result::Result<__Field, D::Error>
|
fn deserialize<D>(deserializer: &mut D) -> ::std::result::Result<__Field, D::Error>
|
||||||
where D: ::serde::de::Deserializer,
|
where D: _serde::de::Deserializer,
|
||||||
{
|
{
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
@@ -1011,25 +1017,25 @@ fn deserialize_field_visitor(
|
|||||||
phantom: PhantomData<D>
|
phantom: PhantomData<D>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<__D> ::serde::de::Visitor for __FieldVisitor<__D>
|
impl<__D> _serde::de::Visitor for __FieldVisitor<__D>
|
||||||
where __D: ::serde::de::Deserializer
|
where __D: _serde::de::Deserializer
|
||||||
{
|
{
|
||||||
type Value = __Field;
|
type Value = __Field;
|
||||||
|
|
||||||
fn visit_usize<E>(&mut self, value: usize) -> ::std::result::Result<__Field, E>
|
fn visit_usize<E>(&mut self, value: usize) -> ::std::result::Result<__Field, E>
|
||||||
where E: ::serde::de::Error,
|
where E: _serde::de::Error,
|
||||||
{
|
{
|
||||||
$index_body
|
$index_body
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_str<E>(&mut self, value: &str) -> ::std::result::Result<__Field, E>
|
fn visit_str<E>(&mut self, value: &str) -> ::std::result::Result<__Field, E>
|
||||||
where E: ::serde::de::Error,
|
where E: _serde::de::Error,
|
||||||
{
|
{
|
||||||
$str_body
|
$str_body
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_bytes<E>(&mut self, value: &[u8]) -> ::std::result::Result<__Field, E>
|
fn visit_bytes<E>(&mut self, value: &[u8]) -> ::std::result::Result<__Field, E>
|
||||||
where E: ::serde::de::Error,
|
where E: _serde::de::Error,
|
||||||
{
|
{
|
||||||
$bytes_body
|
$bytes_body
|
||||||
}
|
}
|
||||||
@@ -1131,7 +1137,7 @@ fn deserialize_map(
|
|||||||
.map(|&(_, _, name)| {
|
.map(|&(_, _, name)| {
|
||||||
quote_arm!(cx,
|
quote_arm!(cx,
|
||||||
__Field::$name => {
|
__Field::$name => {
|
||||||
try!(visitor.visit_value::<::serde::de::impls::IgnoredAny>());
|
try!(visitor.visit_value::<_serde::de::impls::IgnoredAny>());
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -1142,7 +1148,7 @@ fn deserialize_map(
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(quote_arm!(cx,
|
Some(quote_arm!(cx,
|
||||||
_ => { try!(visitor.visit_value::<::serde::de::impls::IgnoredAny>()); }
|
_ => { try!(visitor.visit_value::<_serde::de::impls::IgnoredAny>()); }
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+20
-13
@@ -74,14 +74,21 @@ fn serialize_item(
|
|||||||
|
|
||||||
let where_clause = &impl_generics.where_clause;
|
let where_clause = &impl_generics.where_clause;
|
||||||
|
|
||||||
|
let dummy_const = builder.id(format!("_IMPL_SERIALIZE_FOR_{}", item.ident));
|
||||||
|
|
||||||
Ok(quote_item!(cx,
|
Ok(quote_item!(cx,
|
||||||
impl $impl_generics ::serde::ser::Serialize for $ty $where_clause {
|
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
|
||||||
fn serialize<__S>(&self, _serializer: &mut __S) -> ::std::result::Result<(), __S::Error>
|
const $dummy_const: () = {
|
||||||
where __S: ::serde::ser::Serializer,
|
extern crate serde as _serde;
|
||||||
{
|
#[automatically_derived]
|
||||||
$body
|
impl $impl_generics _serde::ser::Serialize for $ty $where_clause {
|
||||||
|
fn serialize<__S>(&self, _serializer: &mut __S) -> ::std::result::Result<(), __S::Error>
|
||||||
|
where __S: _serde::ser::Serializer,
|
||||||
|
{
|
||||||
|
$body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
).unwrap())
|
).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +103,7 @@ fn build_impl_generics(
|
|||||||
let generics = bound::without_defaults(generics);
|
let generics = bound::without_defaults(generics);
|
||||||
let generics = bound::with_bound(cx, builder, item, &generics,
|
let generics = bound::with_bound(cx, builder, item, &generics,
|
||||||
&serialized_by_us,
|
&serialized_by_us,
|
||||||
&["serde", "ser", "Serialize"]);
|
&builder.path().ids(&["_serde", "ser", "Serialize"]).build());
|
||||||
generics
|
generics
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,7 +368,7 @@ fn serialize_variant(
|
|||||||
|
|
||||||
Ok(quote_arm!(cx,
|
Ok(quote_arm!(cx,
|
||||||
$pat => {
|
$pat => {
|
||||||
::serde::ser::Serializer::serialize_unit_variant(
|
_serde::ser::Serializer::serialize_unit_variant(
|
||||||
_serializer,
|
_serializer,
|
||||||
$type_name,
|
$type_name,
|
||||||
$variant_index,
|
$variant_index,
|
||||||
@@ -380,7 +387,7 @@ fn serialize_variant(
|
|||||||
|
|
||||||
Ok(quote_arm!(cx,
|
Ok(quote_arm!(cx,
|
||||||
$pat => {
|
$pat => {
|
||||||
::serde::ser::Serializer::serialize_newtype_variant(
|
_serde::ser::Serializer::serialize_newtype_variant(
|
||||||
_serializer,
|
_serializer,
|
||||||
$type_name,
|
$type_name,
|
||||||
$variant_index,
|
$variant_index,
|
||||||
@@ -647,12 +654,12 @@ fn serialize_tuple_struct_visitor(
|
|||||||
).unwrap(),
|
).unwrap(),
|
||||||
|
|
||||||
quote_item!(cx,
|
quote_item!(cx,
|
||||||
impl $visitor_impl_generics ::serde::ser::SeqVisitor
|
impl $visitor_impl_generics _serde::ser::SeqVisitor
|
||||||
for Visitor $visitor_generics
|
for Visitor $visitor_generics
|
||||||
$where_clause {
|
$where_clause {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit<S>(&mut self, _serializer: &mut S) -> ::std::result::Result<Option<()>, S::Error>
|
fn visit<S>(&mut self, _serializer: &mut S) -> ::std::result::Result<Option<()>, S::Error>
|
||||||
where S: ::serde::ser::Serializer
|
where S: _serde::ser::Serializer
|
||||||
{
|
{
|
||||||
match self.state {
|
match self.state {
|
||||||
$arms
|
$arms
|
||||||
@@ -752,12 +759,12 @@ fn serialize_struct_visitor(
|
|||||||
|
|
||||||
quote_item!(cx,
|
quote_item!(cx,
|
||||||
impl $visitor_impl_generics
|
impl $visitor_impl_generics
|
||||||
::serde::ser::MapVisitor
|
_serde::ser::MapVisitor
|
||||||
for Visitor $visitor_generics
|
for Visitor $visitor_generics
|
||||||
$where_clause {
|
$where_clause {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit<S>(&mut self, _serializer: &mut S) -> ::std::result::Result<Option<()>, S::Error>
|
fn visit<S>(&mut self, _serializer: &mut S) -> ::std::result::Result<Option<()>, S::Error>
|
||||||
where S: ::serde::ser::Serializer,
|
where S: _serde::ser::Serializer,
|
||||||
{
|
{
|
||||||
loop {
|
loop {
|
||||||
match self.state {
|
match self.state {
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
#![cfg_attr(feature = "nightly", feature(plugin))]
|
#![cfg_attr(feature = "nightly", feature(plugin))]
|
||||||
#![cfg_attr(feature = "nightly", plugin(clippy))]
|
#![cfg_attr(feature = "nightly", plugin(clippy))]
|
||||||
|
|
||||||
extern crate serde;
|
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/test.rs"));
|
include!(concat!(env!("OUT_DIR"), "/test.rs"));
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use serde::{Serialize, Serializer, Deserialize, Deserializer};
|
extern crate serde;
|
||||||
|
use self::serde::{Serialize, Serializer, Deserialize, Deserializer};
|
||||||
|
|
||||||
use token::{
|
use token::{
|
||||||
Error,
|
Error,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use serde;
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::error;
|
use std::error;
|
||||||
use serde::Serialize;
|
|
||||||
use serde::bytes::{ByteBuf, Bytes};
|
extern crate serde;
|
||||||
|
use self::serde::Serialize;
|
||||||
|
use self::serde::bytes::{ByteBuf, Bytes};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
|
|||||||
use std::net;
|
use std::net;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use serde::de::{Deserializer, Visitor};
|
extern crate serde;
|
||||||
|
use self::serde::de::{Deserializer, Visitor};
|
||||||
|
|
||||||
use token::{
|
use token::{
|
||||||
Error,
|
Error,
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ use std::fmt;
|
|||||||
use std::iter;
|
use std::iter;
|
||||||
use std::error;
|
use std::error;
|
||||||
|
|
||||||
use serde::ser::{self, Serialize};
|
extern crate serde;
|
||||||
use serde::de;
|
use self::serde::ser::{self, Serialize};
|
||||||
use serde::de::value::{self, ValueDeserializer};
|
use self::serde::de;
|
||||||
|
use self::serde::de::value::{self, ValueDeserializer};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub enum Token<'a> {
|
pub enum Token<'a> {
|
||||||
|
|||||||
Reference in New Issue
Block a user