mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-25 05:47:56 +00:00
Generate deserialize impls for identifiers
This commit is contained in:
+15
-2
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user