Skip to content

Commit

Permalink
Slightly linearize Variant's parse logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Apr 22, 2021
1 parent b71c788 commit 2fcb301
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,27 +248,26 @@ pub mod parsing {
fn parse(input: ParseStream) -> Result<Self> {
let attrs = input.call(Attribute::parse_outer)?;
let _visibility: Visibility = input.parse()?;
let ident: Ident = input.parse()?;
let fields = if input.peek(token::Brace) {
Fields::Named(input.parse()?)
} else if input.peek(token::Paren) {
Fields::Unnamed(input.parse()?)
} else {
Fields::Unit
};
let discriminant = if input.peek(Token![=]) {
let eq_token: Token![=] = input.parse()?;
let discriminant: Expr = input.parse()?;
Some((eq_token, discriminant))
} else {
None
};
Ok(Variant {
attrs,
ident: input.parse()?,
fields: {
if input.peek(token::Brace) {
Fields::Named(input.parse()?)
} else if input.peek(token::Paren) {
Fields::Unnamed(input.parse()?)
} else {
Fields::Unit
}
},
discriminant: {
if input.peek(Token![=]) {
let eq_token: Token![=] = input.parse()?;
let discriminant: Expr = input.parse()?;
Some((eq_token, discriminant))
} else {
None
}
},
ident,
fields,
discriminant,
})
}
}
Expand Down

0 comments on commit 2fcb301

Please sign in to comment.