Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mrgvsv/to_phantom

Convert generics to PhantomData in proc macros
https://github.com/mrgvsv/to_phantom

Last synced: 13 days ago
JSON representation

Convert generics to PhantomData in proc macros

Awesome Lists containing this project

README

        

# `to_phantom`

[![Crates.io](https://img.shields.io/crates/v/to_phantom)](https://crates.io/crates/to_phantom)
[![Docs](https://img.shields.io/docsrs/to_phantom)](https://docs.rs/to_phantom/latest/to_phantom/)
[![License](https://img.shields.io/crates/l/to_phantom)](https://github.com/MrGVSV/to_phantom/blob/main/License.md)

Easily convert [`Generics`](https://docs.rs/syn/latest/syn/struct.Generics.html)
to [`PhantomData`](https://doc.rust-lang.org/core/marker/struct.PhantomData.html) 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.

```rust
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,
}
}
}
```