Skip to content

Instantly share code, notes, and snippets.

@freedomtowin
Created June 28, 2025 21:17
Show Gist options
  • Save freedomtowin/631e5d347f55d44eb1543cf7d7730ec4 to your computer and use it in GitHub Desktop.
Save freedomtowin/631e5d347f55d44eb1543cf7d7730ec4 to your computer and use it in GitHub Desktop.
Example of creating a Gist using Python
struct ForIfClause {
pattern: Pat,
sequence: Expr,
conditions: Vec<Condition>,
}
impl Parse for ForIfClause {
fn parse(input: ParseStream) -> syn::Result<Self> {
_ = input.parse::<Token![for]>()?;
let pattern = Pat::parse_single(input)?;
_ = input.parse::<Token![in]>()?;
let sequence = input.parse()?;
let conditions = parse_zero_or_more(input);
Ok(Self {
pattern,
sequence,
conditions,
})
}
}
fn parse_zero_or_more<T: Parse>(input: ParseStream) -> Vec<T> {
    let mut result = Vec::new();
    while let Ok(item) = input.parse() {
        result.push(item);
    }
    result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment