If I want to wrap a macro around offset_of!'s nested form, e.g. offset_of!(Foo, x.y.VariantA.0), what should x.y.VariantA.0 get parsed as in syn terms (e.g. which of these https://docs.rs/syn/latest/syn/index.html#structs)?
The closest seems to be ExprField, but afaict that represents just a single field, not the sequence.
ExprField, its base can be any Expr, including Expr::Field(ExprField) and thus allows recursive parsing of "x.y.VariantA.0":
fn main() {
let x: Result<syn::ExprField, _> = syn::parse2("x.y.VariantA.0".parse().unwrap());
dbg!(x);
}
Relevant excerpt of the output:
[src/main.rs:3:5] x = Ok(
ExprField {
base: Expr::Field {
base: Expr::Field {
base: Expr::Path { x },
member: Member::Named( y ),
},
member: Member::Named( VariantA ),
},
member: Member::Unnamed( 0 ),
},
)
Playground
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With