dtolnay / quote

Rust quasi-quoting
Apache License 2.0
1.32k stars 90 forks source link

adding support for std::lazy::Lazy and std::lazy::SyncLazy #187

Closed DzenanJupic closed 3 years ago

DzenanJupic commented 3 years ago

I just ran into a situation where it would be great to have the option to use SyncLazy in quote!.

minimal example:

/* --snip -- */
use proc_macro2::{Ident, Span, TokenStream as TokenStream2};
use std::lazy::SyncLazy;
use quote::quote;

static SOME_GENERIC: SyncLazy<Ident> = SyncLazy(|| Ident::new("GENERIC", Span::call_site()));

fn generate() -> TokenStream2 {
    quote! {
         fn generated<#SOME_GENERIC>(arg: #SOME_GENERIC) {
             /* -- snip -- */
         }
     }
}

To not break builds using the stable compiler, the new implementations are feature gated.