Generate deserialize impls for identifiers

This commit is contained in:
David Tolnay
2017-04-14 16:09:00 -07:00
parent 30e8c84d01
commit cdfd445528
17 changed files with 745 additions and 103 deletions
+15 -2
View File
@@ -12,13 +12,14 @@ use quote::Tokens;
use bound;
use fragment::{Fragment, Stmts, Match};
use internals::ast::{Body, Container, Field, Style, Variant};
use internals::{self, attr};
use internals::{attr, Ctxt};
use std::u32;
pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<Tokens, String> {
let ctxt = internals::Ctxt::new();
let ctxt = Ctxt::new();
let cont = Container::from_ast(&ctxt, input);
precondition(&ctxt, &cont);
try!(ctxt.check());
let ident = &cont.ident;
@@ -61,6 +62,18 @@ pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result<Tokens, Strin
)
}
fn precondition(cx: &Ctxt, cont: &Container) {
match cont.attrs.identifier() {
attr::Identifier::No => {}
attr::Identifier::Field => {
cx.error("field identifiers cannot be serialized");
}
attr::Identifier::Variant => {
cx.error("variant identifiers cannot be serialized");
}
}
}
struct Parameters {
/// Variable holding the value being serialized. Either `self` for local
/// types or `__self` for remote types.