I have a lot of proc-macro code where only certain types of arguments are expected (no lifetimes, no references, generic arguments can only be of type Option, etc.).
Currently my code looks like a match statement after a match statement after a match statement.
Is there any way to make it more readable/more pleasant to write?
I want my code to read something like: convert this syn::Type to syn::TypePath. If it isn't then fail, then gracefully fail.
In this case I want to piggyback off of PathArguments syntax with PropertyName<PropertyType> syntax.
But you are right, this might be easier to do with parse functions:
impl Parse for Prop {
fn parse(input: ParseStream) -> syn::Result<Self> {
let name = input.parse()?;
let _: Token![<] = input.parse()?;
let ty = input.parse()?;
let _: Token![>] = input.parse()?;
Ok(Prop { name, ty })
}
}