Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ece96ac4e5 |
@@ -24,18 +24,11 @@ fn parse_enum_attributes(attrs: &[syn::Attribute]) -> Option<syn::LitStr> {
|
|||||||
.filter(|attr| attr.style == syn::AttrStyle::Outer)
|
.filter(|attr| attr.style == syn::AttrStyle::Outer)
|
||||||
.find_map(|attr| match attr.meta {
|
.find_map(|attr| match attr.meta {
|
||||||
syn::Meta::List(ref meta_list) => {
|
syn::Meta::List(ref meta_list) => {
|
||||||
if let (Some(name), 1) = (
|
if meta_list.path.is_ident("tag") {
|
||||||
meta_list.path.segments.first(),
|
|
||||||
meta_list.path.segments.len(),
|
|
||||||
) {
|
|
||||||
if name.ident == "tag" {
|
|
||||||
Some(meta_list.clone())
|
Some(meta_list.clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
@@ -49,12 +42,7 @@ fn parse_enum_attributes(attrs: &[syn::Attribute]) -> Option<syn::LitStr> {
|
|||||||
syn::Expr::Assign(ref assign) => {
|
syn::Expr::Assign(ref assign) => {
|
||||||
match *assign.left {
|
match *assign.left {
|
||||||
syn::Expr::Path(ref exprpath) => {
|
syn::Expr::Path(ref exprpath) => {
|
||||||
let segments = &exprpath.path.segments;
|
assert!(exprpath.path.is_ident("rename"), "invalid attribute key");
|
||||||
let (Some(segment), 1) = (segments.first(), segments.len()) else {
|
|
||||||
panic!("invalid attribute key")
|
|
||||||
};
|
|
||||||
|
|
||||||
assert!(segment.ident == "rename", "invalid attribute key");
|
|
||||||
}
|
}
|
||||||
_ => panic!("invalid expression in enum variant attribute, left side"),
|
_ => panic!("invalid expression in enum variant attribute, left side"),
|
||||||
}
|
}
|
||||||
@@ -103,24 +91,18 @@ fn parse_tag_attribute(expr: syn::Expr, elem: &syn::Data) -> Translator {
|
|||||||
|
|
||||||
match *assign.left {
|
match *assign.left {
|
||||||
syn::Expr::Path(ref exprpath) => {
|
syn::Expr::Path(ref exprpath) => {
|
||||||
let segments = &exprpath.path.segments;
|
assert!(exprpath.path.is_ident("translate"), "invalid attribute key");
|
||||||
let (Some(segment), 1) = (segments.first(), segments.len()) else {
|
|
||||||
panic!("invalid attribute key")
|
|
||||||
};
|
|
||||||
|
|
||||||
assert!(segment.ident == "translate", "invalid attribute key");
|
|
||||||
}
|
}
|
||||||
_ => panic!("invalid expression in tag field attribute, left side"),
|
_ => panic!("invalid expression in tag field attribute, left side"),
|
||||||
}
|
}
|
||||||
|
|
||||||
match *assign.right {
|
match *assign.right {
|
||||||
syn::Expr::Path(ref exprpath) => {
|
syn::Expr::Path(ref exprpath) => {
|
||||||
let segments = &exprpath.path.segments;
|
let Some(ident) = exprpath.path.get_ident() else {
|
||||||
let (Some(segment), 1) = (segments.first(), segments.len()) else {
|
|
||||||
panic!("invalid attribute key")
|
panic!("invalid attribute key")
|
||||||
};
|
};
|
||||||
|
|
||||||
match segment.ident.to_string().as_str() {
|
match ident.to_string().as_str() {
|
||||||
"serde" => Translator::Serde,
|
"serde" => Translator::Serde,
|
||||||
"manual" => Translator::Manual,
|
"manual" => Translator::Manual,
|
||||||
"transparent" =>
|
"transparent" =>
|
||||||
|
|||||||
@@ -26,13 +26,7 @@ struct Element {
|
|||||||
|
|
||||||
fn is_cfg_attribute(attr: &syn::Attribute) -> bool {
|
fn is_cfg_attribute(attr: &syn::Attribute) -> bool {
|
||||||
match attr.meta {
|
match attr.meta {
|
||||||
syn::Meta::List(ref meta_list) => {
|
syn::Meta::List(ref meta_list) => meta_list.path.is_ident("cfg"),
|
||||||
let segments = &meta_list.path.segments;
|
|
||||||
match (segments.first(), segments.len()) {
|
|
||||||
(Some(segment), 1) => segment.ident == "cfg",
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,16 +87,11 @@ fn parse_field_attrs(attrs: &mut Vec<syn::Attribute>) -> Option<String> {
|
|||||||
.filter(|&(_i, attr)| attr.style == syn::AttrStyle::Outer)
|
.filter(|&(_i, attr)| attr.style == syn::AttrStyle::Outer)
|
||||||
.find_map(|(i, attr)| match attr.meta {
|
.find_map(|(i, attr)| match attr.meta {
|
||||||
syn::Meta::List(ref meta_list) => {
|
syn::Meta::List(ref meta_list) => {
|
||||||
let tag = &meta_list.path;
|
if meta_list.path.is_ident("tag") {
|
||||||
if let (Some(segment), 1) = (tag.segments.first(), tag.segments.len()) {
|
|
||||||
if segment.ident == "tag" {
|
|
||||||
Some((i, meta_list.clone()))
|
Some((i, meta_list.clone()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
@@ -123,12 +112,10 @@ fn parse_field_attrs(attrs: &mut Vec<syn::Attribute>) -> Option<String> {
|
|||||||
|
|
||||||
match *assign.left {
|
match *assign.left {
|
||||||
syn::Expr::Path(ref exprpath) => {
|
syn::Expr::Path(ref exprpath) => {
|
||||||
let segments = &exprpath.path.segments;
|
assert!(
|
||||||
let (Some(segment), 1) = (segments.first(), segments.len()) else {
|
exprpath.path.is_ident("key"),
|
||||||
panic!("invalid tag field attribute key")
|
"invalid tag field attribute key"
|
||||||
};
|
);
|
||||||
|
|
||||||
assert!(segment.ident == "key", "invalid tag field attribute key");
|
|
||||||
}
|
}
|
||||||
_ => panic!("invalid expression in tag field attribute, left side"),
|
_ => panic!("invalid expression in tag field attribute, left side"),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user