Update derive parsing to produce structured representation
diff --git a/syntax/attrs.rs b/syntax/attrs.rs
index 6d661ba..798cbee 100644
--- a/syntax/attrs.rs
+++ b/syntax/attrs.rs
@@ -13,7 +13,7 @@
pub(super) fn parse(
attrs: &[Attribute],
doc: &mut Doc,
- mut derives: Option<&mut Vec<Ident>>,
+ mut derives: Option<&mut Vec<Derive>>,
) -> Result<()> {
for attr in attrs {
if attr.path.is_ident("doc") {
@@ -37,13 +37,17 @@
Ok(lit)
}
-fn parse_derive_attribute(input: ParseStream) -> Result<Vec<Ident>> {
+fn parse_derive_attribute(input: ParseStream) -> Result<Vec<Derive>> {
input
.parse_terminated::<Path, Token![,]>(Path::parse_mod_style)?
.into_iter()
- .map(|path| match path.get_ident() {
- Some(ident) if Derive::from(ident).is_some() => Ok(ident.clone()),
- _ => Err(Error::new_spanned(path, "unsupported derive")),
+ .map(|path| {
+ if let Some(ident) = path.get_ident() {
+ if let Some(derive) = Derive::from(ident) {
+ return Ok(derive);
+ }
+ }
+ Err(Error::new_spanned(path, "unsupported derive"))
})
.collect()
}
diff --git a/syntax/mod.rs b/syntax/mod.rs
index 3eb6c6e..9e4cbbc 100644
--- a/syntax/mod.rs
+++ b/syntax/mod.rs
@@ -46,7 +46,7 @@
pub struct Struct {
pub doc: Doc,
- pub derives: Vec<Ident>,
+ pub derives: Vec<Derive>,
pub struct_token: Token![struct],
pub ident: Ident,
pub brace_token: Brace,
diff --git a/syntax/tokens.rs b/syntax/tokens.rs
index 6dd6073..9a1fee0 100644
--- a/syntax/tokens.rs
+++ b/syntax/tokens.rs
@@ -71,11 +71,7 @@
impl ToTokens for Derive {
fn to_tokens(&self, tokens: &mut TokenStream) {
- let name = match self {
- Derive::Clone => "Clone",
- Derive::Copy => "Copy",
- };
- Ident::new(name, Span::call_site()).to_tokens(tokens);
+ Ident::new(self.as_ref(), Span::call_site()).to_tokens(tokens);
}
}