Skip to content

Commit

Permalink
Simplified the FromAttribute for FieldAttribute implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorKoenders committed Dec 10, 2021
1 parent 900af4b commit 268a796
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,18 @@ enum FieldAttribute {

impl FromAttribute for FieldAttribute {
fn parse(group: &Group) -> Result<Option<Self>> {
match virtue::utils::parse_tagged_attribute(group, "bincode") {
Some(body) => match body.into_iter().next() {
Some(TokenTree::Ident(ident)) if ident.to_string() == "with_serde" => {
Ok(Some(Self::WithSerde))
}
token => Err(virtue::Error::custom_at_opt_token(
"Unknown attribute, expected one of: \"with_serde\"",
token,
)),
},
None => Ok(None),
let body = match virtue::utils::parse_tagged_attribute(group, "bincode") {
Some(body) => body,
None => return Ok(None),
};
match body.into_iter().next() {
Some(TokenTree::Ident(ident)) if ident.to_string() == "with_serde" => {
Ok(Some(Self::WithSerde))
}
token => Err(virtue::Error::custom_at_opt_token(
"Unknown attribute, expected one of: \"with_serde\"",
token,
)),
}
}
}

0 comments on commit 268a796

Please sign in to comment.