mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 17:11:02 +00:00
Rename serde_item to serde_internals
This commit is contained in:
@@ -18,7 +18,7 @@ with-syntex = [
|
|||||||
"quasi/with-syntex",
|
"quasi/with-syntex",
|
||||||
"quasi_codegen",
|
"quasi_codegen",
|
||||||
"quasi_codegen/with-syntex",
|
"quasi_codegen/with-syntex",
|
||||||
"serde_item/with-syntex",
|
"serde_internals/with-syntex",
|
||||||
"syntex",
|
"syntex",
|
||||||
"syntex_syntax",
|
"syntex_syntax",
|
||||||
]
|
]
|
||||||
@@ -32,6 +32,6 @@ aster = { version = "^0.19.0", default-features = false }
|
|||||||
clippy = { version = "^0.*", optional = true }
|
clippy = { version = "^0.*", optional = true }
|
||||||
quasi = { version = "^0.13.0", default-features = false }
|
quasi = { version = "^0.13.0", default-features = false }
|
||||||
quasi_macros = { version = "^0.13.0", optional = true }
|
quasi_macros = { version = "^0.13.0", optional = true }
|
||||||
serde_item = { version = "^0.2.0", path = "../serde_item", default-features = false }
|
serde_internals = { version = "^0.1.0", path = "../serde_internals", default-features = false }
|
||||||
syntex = { version = "^0.36.0", optional = true }
|
syntex = { version = "^0.36.0", optional = true }
|
||||||
syntex_syntax = { version = "^0.36.0", optional = true }
|
syntex_syntax = { version = "^0.36.0", optional = true }
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use syntax::ast;
|
|||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::visit;
|
use syntax::visit;
|
||||||
|
|
||||||
use item::{attr, Item};
|
use internals::{attr, Item};
|
||||||
|
|
||||||
// Remove the default from every type parameter because in the generated impls
|
// Remove the default from every type parameter because in the generated impls
|
||||||
// they look like associated types: "error: associated type bindings are not
|
// they look like associated types: "error: associated type bindings are not
|
||||||
|
|||||||
+28
-29
@@ -7,8 +7,7 @@ use syntax::parse::token::InternedString;
|
|||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
|
|
||||||
use bound;
|
use bound;
|
||||||
use error::Error;
|
use internals::{attr, Body, Error, Field, Item, Style, Variant};
|
||||||
use item::{self, attr};
|
|
||||||
|
|
||||||
pub fn expand_derive_deserialize(
|
pub fn expand_derive_deserialize(
|
||||||
cx: &mut ExtCtxt,
|
cx: &mut ExtCtxt,
|
||||||
@@ -27,9 +26,9 @@ pub fn expand_derive_deserialize(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let item = match item::Item::from_ast(cx, item) {
|
let item = match Item::from_ast(cx, item) {
|
||||||
Ok(item) => item,
|
Ok(item) => item,
|
||||||
Err(item::Error::UnexpectedItemKind) => {
|
Err(Error::UnexpectedItemKind) => {
|
||||||
cx.span_err(item.span,
|
cx.span_err(item.span,
|
||||||
"`#[derive(Deserialize)]` may only be applied to structs and enums");
|
"`#[derive(Deserialize)]` may only be applied to structs and enums");
|
||||||
return;
|
return;
|
||||||
@@ -49,7 +48,7 @@ pub fn expand_derive_deserialize(
|
|||||||
fn deserialize_item(
|
fn deserialize_item(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
item: &item::Item,
|
item: &Item,
|
||||||
) -> P<ast::Item> {
|
) -> P<ast::Item> {
|
||||||
let impl_generics = build_impl_generics(builder, &item);
|
let impl_generics = build_impl_generics(builder, &item);
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ fn deserialize_item(
|
|||||||
// each generic field type that will be set to a default value.
|
// each generic field type that will be set to a default value.
|
||||||
fn build_impl_generics(
|
fn build_impl_generics(
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
item: &item::Item,
|
item: &Item,
|
||||||
) -> ast::Generics {
|
) -> ast::Generics {
|
||||||
let generics = bound::without_defaults(item.generics);
|
let generics = bound::without_defaults(item.generics);
|
||||||
|
|
||||||
@@ -131,12 +130,12 @@ fn requires_default(attrs: &attr::Field) -> bool {
|
|||||||
fn deserialize_body(
|
fn deserialize_body(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
item: &item::Item,
|
item: &Item,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
match item.body {
|
match item.body {
|
||||||
item::Body::Enum(ref variants) => {
|
Body::Enum(ref variants) => {
|
||||||
deserialize_item_enum(
|
deserialize_item_enum(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
@@ -146,7 +145,7 @@ fn deserialize_body(
|
|||||||
variants,
|
variants,
|
||||||
&item.attrs)
|
&item.attrs)
|
||||||
}
|
}
|
||||||
item::Body::Struct(item::Style::Struct, ref fields) => {
|
Body::Struct(Style::Struct, ref fields) => {
|
||||||
if fields.iter().any(|field| field.ident.is_none()) {
|
if fields.iter().any(|field| field.ident.is_none()) {
|
||||||
cx.span_bug(item.span, "struct has unnamed fields")
|
cx.span_bug(item.span, "struct has unnamed fields")
|
||||||
}
|
}
|
||||||
@@ -161,8 +160,8 @@ fn deserialize_body(
|
|||||||
fields,
|
fields,
|
||||||
&item.attrs)
|
&item.attrs)
|
||||||
}
|
}
|
||||||
item::Body::Struct(item::Style::Tuple, ref fields) |
|
Body::Struct(Style::Tuple, ref fields) |
|
||||||
item::Body::Struct(item::Style::Newtype, ref fields) => {
|
Body::Struct(Style::Newtype, ref fields) => {
|
||||||
if fields.iter().any(|field| field.ident.is_some()) {
|
if fields.iter().any(|field| field.ident.is_some()) {
|
||||||
cx.span_bug(item.span, "tuple struct has named fields")
|
cx.span_bug(item.span, "tuple struct has named fields")
|
||||||
}
|
}
|
||||||
@@ -177,7 +176,7 @@ fn deserialize_body(
|
|||||||
fields,
|
fields,
|
||||||
&item.attrs)
|
&item.attrs)
|
||||||
}
|
}
|
||||||
item::Body::Struct(item::Style::Unit, _) => {
|
Body::Struct(Style::Unit, _) => {
|
||||||
deserialize_unit_struct(
|
deserialize_unit_struct(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
@@ -308,7 +307,7 @@ fn deserialize_tuple(
|
|||||||
variant_ident: Option<Ident>,
|
variant_ident: Option<Ident>,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let where_clause = &impl_generics.where_clause;
|
let where_clause = &impl_generics.where_clause;
|
||||||
@@ -390,7 +389,7 @@ fn deserialize_seq(
|
|||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
type_path: ast::Path,
|
type_path: ast::Path,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
is_struct: bool,
|
is_struct: bool,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let let_values: Vec<_> = fields.iter()
|
let let_values: Vec<_> = fields.iter()
|
||||||
@@ -470,7 +469,7 @@ fn deserialize_newtype_struct(
|
|||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
type_path: &ast::Path,
|
type_path: &ast::Path,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
field: &item::Field,
|
field: &Field,
|
||||||
) -> Vec<ast::TokenTree> {
|
) -> Vec<ast::TokenTree> {
|
||||||
let value = match field.attrs.deserialize_with() {
|
let value = match field.attrs.deserialize_with() {
|
||||||
None => {
|
None => {
|
||||||
@@ -505,7 +504,7 @@ fn deserialize_struct(
|
|||||||
variant_ident: Option<Ident>,
|
variant_ident: Option<Ident>,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let where_clause = &impl_generics.where_clause;
|
let where_clause = &impl_generics.where_clause;
|
||||||
@@ -587,7 +586,7 @@ fn deserialize_item_enum(
|
|||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
variants: &[item::Variant],
|
variants: &[Variant],
|
||||||
item_attrs: &attr::Item
|
item_attrs: &attr::Item
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let where_clause = &impl_generics.where_clause;
|
let where_clause = &impl_generics.where_clause;
|
||||||
@@ -678,19 +677,19 @@ fn deserialize_variant(
|
|||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
generics: &ast::Generics,
|
generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
variant: &item::Variant,
|
variant: &Variant,
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let variant_ident = variant.ident;
|
let variant_ident = variant.ident;
|
||||||
|
|
||||||
match variant.style {
|
match variant.style {
|
||||||
item::Style::Unit => {
|
Style::Unit => {
|
||||||
quote_expr!(cx, {
|
quote_expr!(cx, {
|
||||||
try!(visitor.visit_unit());
|
try!(visitor.visit_unit());
|
||||||
Ok($type_ident::$variant_ident)
|
Ok($type_ident::$variant_ident)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
item::Style::Newtype => {
|
Style::Newtype => {
|
||||||
deserialize_newtype_variant(
|
deserialize_newtype_variant(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
@@ -700,7 +699,7 @@ fn deserialize_variant(
|
|||||||
&variant.fields[0],
|
&variant.fields[0],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
item::Style::Tuple => {
|
Style::Tuple => {
|
||||||
deserialize_tuple(
|
deserialize_tuple(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
@@ -712,7 +711,7 @@ fn deserialize_variant(
|
|||||||
item_attrs,
|
item_attrs,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
item::Style::Struct => {
|
Style::Struct => {
|
||||||
deserialize_struct(
|
deserialize_struct(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
@@ -733,7 +732,7 @@ fn deserialize_newtype_variant(
|
|||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
variant_ident: Ident,
|
variant_ident: Ident,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
field: &item::Field,
|
field: &Field,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let visit = match field.attrs.deserialize_with() {
|
let visit = match field.attrs.deserialize_with() {
|
||||||
None => {
|
None => {
|
||||||
@@ -919,7 +918,7 @@ fn deserialize_struct_visitor(
|
|||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
struct_path: ast::Path,
|
struct_path: ast::Path,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> (Vec<P<ast::Item>>, ast::Stmt, P<ast::Expr>) {
|
) -> (Vec<P<ast::Item>>, ast::Stmt, P<ast::Expr>) {
|
||||||
let field_exprs = fields.iter()
|
let field_exprs = fields.iter()
|
||||||
@@ -971,7 +970,7 @@ fn deserialize_map(
|
|||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
struct_path: ast::Path,
|
struct_path: ast::Path,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
// Create the field names for the fields.
|
// Create the field names for the fields.
|
||||||
@@ -1187,14 +1186,14 @@ fn name_expr(
|
|||||||
|
|
||||||
fn check_no_str(
|
fn check_no_str(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
item: &item::Item,
|
item: &Item,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), ()> {
|
||||||
let fail = |field: &item::Field| {
|
let fail = |field: &Field| {
|
||||||
cx.span_err(
|
cx.span_err(
|
||||||
field.span,
|
field.span,
|
||||||
"Serde does not support deserializing fields of type &str; \
|
"Serde does not support deserializing fields of type &str; \
|
||||||
consider using String instead");
|
consider using String instead");
|
||||||
Err(Error)
|
Err(())
|
||||||
};
|
};
|
||||||
|
|
||||||
for field in item.body.all_fields() {
|
for field in item.body.all_fields() {
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
/// Error returned if failed to parse attribute.
|
|
||||||
pub struct Error;
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
extern crate aster;
|
extern crate aster;
|
||||||
extern crate quasi;
|
extern crate quasi;
|
||||||
extern crate serde_item as item;
|
extern crate serde_internals as internals;
|
||||||
|
|
||||||
#[cfg(feature = "with-syntex")]
|
#[cfg(feature = "with-syntex")]
|
||||||
extern crate syntex;
|
extern crate syntex;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
mod bound;
|
mod bound;
|
||||||
mod de;
|
mod de;
|
||||||
mod error;
|
|
||||||
mod ser;
|
mod ser;
|
||||||
|
|||||||
+25
-25
@@ -6,7 +6,7 @@ use syntax::ext::base::{Annotatable, ExtCtxt};
|
|||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
|
|
||||||
use bound;
|
use bound;
|
||||||
use item::{self, attr};
|
use internals::{attr, Body, Error, Field, Item, Style, Variant};
|
||||||
|
|
||||||
pub fn expand_derive_serialize(
|
pub fn expand_derive_serialize(
|
||||||
cx: &mut ExtCtxt,
|
cx: &mut ExtCtxt,
|
||||||
@@ -25,9 +25,9 @@ pub fn expand_derive_serialize(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let item = match item::Item::from_ast(cx, item) {
|
let item = match Item::from_ast(cx, item) {
|
||||||
Ok(item) => item,
|
Ok(item) => item,
|
||||||
Err(item::Error::UnexpectedItemKind) => {
|
Err(Error::UnexpectedItemKind) => {
|
||||||
cx.span_err(item.span,
|
cx.span_err(item.span,
|
||||||
"`#[derive(Serialize)]` may only be applied to structs and enums");
|
"`#[derive(Serialize)]` may only be applied to structs and enums");
|
||||||
return;
|
return;
|
||||||
@@ -43,7 +43,7 @@ pub fn expand_derive_serialize(
|
|||||||
fn serialize_item(
|
fn serialize_item(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
item: &item::Item,
|
item: &Item,
|
||||||
) -> P<ast::Item> {
|
) -> P<ast::Item> {
|
||||||
let impl_generics = build_impl_generics(builder, &item);
|
let impl_generics = build_impl_generics(builder, &item);
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ fn serialize_item(
|
|||||||
// field type that will be serialized by us.
|
// field type that will be serialized by us.
|
||||||
fn build_impl_generics(
|
fn build_impl_generics(
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
item: &item::Item,
|
item: &Item,
|
||||||
) -> ast::Generics {
|
) -> ast::Generics {
|
||||||
let generics = bound::without_defaults(item.generics);
|
let generics = bound::without_defaults(item.generics);
|
||||||
|
|
||||||
@@ -114,12 +114,12 @@ fn needs_serialize_bound(attrs: &attr::Field) -> bool {
|
|||||||
fn serialize_body(
|
fn serialize_body(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
item: &item::Item,
|
item: &Item,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
match item.body {
|
match item.body {
|
||||||
item::Body::Enum(ref variants) => {
|
Body::Enum(ref variants) => {
|
||||||
serialize_item_enum(
|
serialize_item_enum(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
@@ -129,7 +129,7 @@ fn serialize_body(
|
|||||||
variants,
|
variants,
|
||||||
&item.attrs)
|
&item.attrs)
|
||||||
}
|
}
|
||||||
item::Body::Struct(item::Style::Struct, ref fields) => {
|
Body::Struct(Style::Struct, ref fields) => {
|
||||||
if fields.iter().any(|field| field.ident.is_none()) {
|
if fields.iter().any(|field| field.ident.is_none()) {
|
||||||
cx.span_bug(item.span, "struct has unnamed fields")
|
cx.span_bug(item.span, "struct has unnamed fields")
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ fn serialize_body(
|
|||||||
fields,
|
fields,
|
||||||
&item.attrs)
|
&item.attrs)
|
||||||
}
|
}
|
||||||
item::Body::Struct(item::Style::Tuple, ref fields) => {
|
Body::Struct(Style::Tuple, ref fields) => {
|
||||||
if fields.iter().any(|field| field.ident.is_some()) {
|
if fields.iter().any(|field| field.ident.is_some()) {
|
||||||
cx.span_bug(item.span, "tuple struct has named fields")
|
cx.span_bug(item.span, "tuple struct has named fields")
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ fn serialize_body(
|
|||||||
fields,
|
fields,
|
||||||
&item.attrs)
|
&item.attrs)
|
||||||
}
|
}
|
||||||
item::Body::Struct(item::Style::Newtype, ref fields) => {
|
Body::Struct(Style::Newtype, ref fields) => {
|
||||||
serialize_newtype_struct(
|
serialize_newtype_struct(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
@@ -164,7 +164,7 @@ fn serialize_body(
|
|||||||
&fields[0],
|
&fields[0],
|
||||||
&item.attrs)
|
&item.attrs)
|
||||||
}
|
}
|
||||||
item::Body::Struct(item::Style::Unit, _) => {
|
Body::Struct(Style::Unit, _) => {
|
||||||
serialize_unit_struct(
|
serialize_unit_struct(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
@@ -190,7 +190,7 @@ fn serialize_newtype_struct(
|
|||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
item_ty: P<ast::Ty>,
|
item_ty: P<ast::Ty>,
|
||||||
field: &item::Field,
|
field: &Field,
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let type_name = name_expr(builder, item_attrs.name());
|
let type_name = name_expr(builder, item_attrs.name());
|
||||||
@@ -211,7 +211,7 @@ fn serialize_tuple_struct(
|
|||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let (visitor_struct, visitor_impl) = serialize_tuple_struct_visitor(
|
let (visitor_struct, visitor_impl) = serialize_tuple_struct_visitor(
|
||||||
@@ -246,7 +246,7 @@ fn serialize_struct(
|
|||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let (visitor_struct, visitor_impl) = serialize_struct_visitor(
|
let (visitor_struct, visitor_impl) = serialize_struct_visitor(
|
||||||
@@ -282,7 +282,7 @@ fn serialize_item_enum(
|
|||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
impl_generics: &ast::Generics,
|
impl_generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
variants: &[item::Variant],
|
variants: &[Variant],
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let arms: Vec<_> =
|
let arms: Vec<_> =
|
||||||
@@ -315,7 +315,7 @@ fn serialize_variant(
|
|||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
generics: &ast::Generics,
|
generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
variant: &item::Variant,
|
variant: &Variant,
|
||||||
variant_index: usize,
|
variant_index: usize,
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> ast::Arm {
|
) -> ast::Arm {
|
||||||
@@ -325,7 +325,7 @@ fn serialize_variant(
|
|||||||
let variant_name = name_expr(builder, variant.attrs.name());
|
let variant_name = name_expr(builder, variant.attrs.name());
|
||||||
|
|
||||||
match variant.style {
|
match variant.style {
|
||||||
item::Style::Unit => {
|
Style::Unit => {
|
||||||
quote_arm!(cx,
|
quote_arm!(cx,
|
||||||
$type_ident::$variant_ident => {
|
$type_ident::$variant_ident => {
|
||||||
_serde::ser::Serializer::serialize_unit_variant(
|
_serde::ser::Serializer::serialize_unit_variant(
|
||||||
@@ -337,7 +337,7 @@ fn serialize_variant(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
item::Style::Newtype => {
|
Style::Newtype => {
|
||||||
let expr = serialize_newtype_variant(
|
let expr = serialize_newtype_variant(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
@@ -353,7 +353,7 @@ fn serialize_variant(
|
|||||||
$type_ident::$variant_ident(ref __simple_value) => { $expr }
|
$type_ident::$variant_ident(ref __simple_value) => { $expr }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
item::Style::Tuple => {
|
Style::Tuple => {
|
||||||
let field_names: Vec<ast::Ident> = (0 .. variant.fields.len())
|
let field_names: Vec<ast::Ident> = (0 .. variant.fields.len())
|
||||||
.map(|i| builder.id(format!("__field{}", i)))
|
.map(|i| builder.id(format!("__field{}", i)))
|
||||||
.collect();
|
.collect();
|
||||||
@@ -382,7 +382,7 @@ fn serialize_variant(
|
|||||||
$pat => { $expr }
|
$pat => { $expr }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
item::Style::Struct => {
|
Style::Struct => {
|
||||||
let field_names: Vec<_> = (0 .. variant.fields.len())
|
let field_names: Vec<_> = (0 .. variant.fields.len())
|
||||||
.map(|i| builder.id(format!("__field{}", i)))
|
.map(|i| builder.id(format!("__field{}", i)))
|
||||||
.collect();
|
.collect();
|
||||||
@@ -432,7 +432,7 @@ fn serialize_newtype_variant(
|
|||||||
variant_name: P<ast::Expr>,
|
variant_name: P<ast::Expr>,
|
||||||
item_ty: P<ast::Ty>,
|
item_ty: P<ast::Ty>,
|
||||||
generics: &ast::Generics,
|
generics: &ast::Generics,
|
||||||
field: &item::Field,
|
field: &Field,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let mut field_expr = quote_expr!(cx, __simple_value);
|
let mut field_expr = quote_expr!(cx, __simple_value);
|
||||||
if let Some(path) = field.attrs.serialize_with() {
|
if let Some(path) = field.attrs.serialize_with() {
|
||||||
@@ -459,7 +459,7 @@ fn serialize_tuple_variant(
|
|||||||
variant_name: P<ast::Expr>,
|
variant_name: P<ast::Expr>,
|
||||||
generics: &ast::Generics,
|
generics: &ast::Generics,
|
||||||
structure_ty: P<ast::Ty>,
|
structure_ty: P<ast::Ty>,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
field_names: Vec<Ident>,
|
field_names: Vec<Ident>,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let variant_ty = builder.ty().tuple()
|
let variant_ty = builder.ty().tuple()
|
||||||
@@ -510,7 +510,7 @@ fn serialize_struct_variant(
|
|||||||
variant_name: P<ast::Expr>,
|
variant_name: P<ast::Expr>,
|
||||||
generics: &ast::Generics,
|
generics: &ast::Generics,
|
||||||
ty: P<ast::Ty>,
|
ty: P<ast::Ty>,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
field_names: Vec<Ident>,
|
field_names: Vec<Ident>,
|
||||||
item_attrs: &attr::Item,
|
item_attrs: &attr::Item,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
@@ -597,7 +597,7 @@ fn serialize_tuple_struct_visitor(
|
|||||||
structure_ty: P<ast::Ty>,
|
structure_ty: P<ast::Ty>,
|
||||||
variant_ty: P<ast::Ty>,
|
variant_ty: P<ast::Ty>,
|
||||||
serializer_method: ast::Ident,
|
serializer_method: ast::Ident,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
generics: &ast::Generics,
|
generics: &ast::Generics,
|
||||||
is_enum: bool,
|
is_enum: bool,
|
||||||
) -> (P<ast::Item>, P<ast::Item>) {
|
) -> (P<ast::Item>, P<ast::Item>) {
|
||||||
@@ -678,7 +678,7 @@ fn serialize_struct_visitor(
|
|||||||
structure_ty: P<ast::Ty>,
|
structure_ty: P<ast::Ty>,
|
||||||
variant_ty: P<ast::Ty>,
|
variant_ty: P<ast::Ty>,
|
||||||
serializer_method: ast::Ident,
|
serializer_method: ast::Ident,
|
||||||
fields: &[item::Field],
|
fields: &[Field],
|
||||||
generics: &ast::Generics,
|
generics: &ast::Generics,
|
||||||
is_enum: bool,
|
is_enum: bool,
|
||||||
) -> (P<ast::Item>, P<ast::Item>) {
|
) -> (P<ast::Item>, P<ast::Item>) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "serde_item"
|
name = "serde_internals"
|
||||||
version = "0.2.0"
|
version = "0.1.0"
|
||||||
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
authors = ["Erick Tryzelaar <erick.tryzelaar@gmail.com>"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
description = "AST representation used by Serde codegen. Unstable."
|
description = "AST representation used by Serde codegen. Unstable."
|
||||||
Reference in New Issue
Block a user