1 unstable release

0.1.0 Apr 28, 2023

#1717 in Procedural macros

Download history 6/week @ 2024-11-13 21/week @ 2024-11-20 27/week @ 2024-11-27 30/week @ 2024-12-04 33/week @ 2024-12-11 13/week @ 2024-12-18 3/week @ 2025-01-01 7/week @ 2025-01-08 23/week @ 2025-01-15 10/week @ 2025-01-22 4/week @ 2025-01-29 15/week @ 2025-02-05 7/week @ 2025-02-12 7/week @ 2025-02-19 22/week @ 2025-02-26

53 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

~205–640KB
~15K SLoC