1 unstable release

0.1.0 Apr 28, 2023

#1431 in Procedural macros

Download history 11/week @ 2024-07-22 24/week @ 2024-07-29 15/week @ 2024-08-05 24/week @ 2024-08-12 29/week @ 2024-08-19 49/week @ 2024-08-26 34/week @ 2024-09-02 19/week @ 2024-09-09 25/week @ 2024-09-16 46/week @ 2024-09-23 39/week @ 2024-09-30 2/week @ 2024-10-07 17/week @ 2024-10-14 22/week @ 2024-10-21 17/week @ 2024-10-28 13/week @ 2024-11-04

69 downloads per month
Used in 6 crates (3 directly)

MIT/Apache

9KB
57 lines

to_phantom

Crates.io Docs License

Easily convert Generics to PhantomData in your proc macros.

This is useful for when creating custom types in a proc macro that use the generics from some other type. The PhantomData allows those generics to exist on the type without needing dedicated fields using them.

use to_phantom::ToPhantom;

fn create_helper(input: DeriveInput) -> TokenStream {
    let generics = input.generics();
    let phantom = generics.to_phantom();

    quote! {
        pub struct MyHelperStruct #generics {
            phantom: #phantom,
        }
    }
}

Dependencies

~225–670KB
~16K SLoC