Skip to content

Implement quote::ToTokens for FoundCrate#68

Open
wojciech-graj wants to merge 1 commit into
bkchr:masterfrom
Lightyear-Layer:to-tokens
Open

Implement quote::ToTokens for FoundCrate#68
wojciech-graj wants to merge 1 commit into
bkchr:masterfrom
Lightyear-Layer:to-tokens

Conversation

@wojciech-graj
Copy link
Copy Markdown

This crate's primary use-case is to find the name of a crate so it can be used in generated code. This code will almost always be generated using the quote macro, meaning you'll pretty much always need to do the conversion shown in the README:

match found_crate {
    FoundCrate::Itself => quote!( crate::Something ),
    FoundCrate::Name(name) => {
        let ident = Ident::new(&name, Span::call_site());
        quote!( #ident::Something )
    }
};

This commit implements quote::ToTokens, so you can use FoundCrate directly in the quote macro.

This crate's primary use-case is to find the name of a crate so it can
be used in generated code. This code will almost always be generated
using the `quote` macro, meaning you'll pretty much always need to do
the conversion shown in the README:

    match found_crate {
        FoundCrate::Itself => quote!( crate::Something ),
        FoundCrate::Name(name) => {
            let ident = Ident::new(&name, Span::call_site());
            quote!( #ident::Something )
        }
    };

This commit implements quote::ToTokens, so you can use FoundCrate
directly in the quote macro.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant