Calling static method of dynamic name struct inside quote!

Hello. I'm writing a macro and want to instantiate a struct by calling Struct::new();
The problem is struct's name is dynamic and inside variable:

let struct_name = format!("QueryBuilderCake");
let gen = quote! {
    #struct_name::new()
}

And for some reason I get an error:

^^^ expected one of ., ;, ?, }, or an operator

But if I replace it with QueryBuilderCake::new() it will work just fine....

you need format_ident!(), not the standard format!()

2 Likes

Oh, I missed it, thank you a lot!