dtolnay / syn

Parser for Rust source code
Apache License 2.0
2.88k stars 311 forks source link

parse_parens, parse_braces, parse_brackets and structs returned by them are public API now. #1592

Closed rrupy closed 7 months ago

rrupy commented 8 months ago

1519

parenthesized!, braced! and bracketed! macros are very verbous in situations where you want to handle Err in current function beacause in this case they are expand in return statement. That's why they must be public.

Code example:

If you have an optional code in parentheses and you don't need the paren token:

if input.peek(token::Paren) {
    let paren_content;
    parenthesized!(paren_content in input);
    paren_content.parse::<ExprUnsafe>()?;
}

vs

if let Ok(Parens { token: _, content}) = parse_parens(input) {
    content.parse::<ExprUnsafe>()?;
}