frunk_derives/lib.rs
1#![recursion_limit = "128"]
2#![doc(html_playground_url = "https://play.rust-lang.org/")]
3//! Frunk Derives
4//!
5//! This library holds logic for the nice custom derives in Frunk.
6//!
7//! Links:
8//! 1. [Source on Github](https://github.com/lloydmeta/frunk)
9//! 2. [Crates.io page](https://crates.io/crates/frunk)
10
11extern crate frunk_proc_macro_helpers;
12extern crate proc_macro;
13
14#[macro_use]
15extern crate quote;
16extern crate syn;
17
18use proc_macro::TokenStream;
19
20mod derive_generic;
21use crate::derive_generic::impl_generic;
22
23mod derive_labelled_generic;
24use crate::derive_labelled_generic::impl_labelled_generic;
25
26use quote::ToTokens;
27
28/// Derives a Generic instance based on HList for
29/// a given Struct or Tuple Struct
30#[proc_macro_derive(Generic)]
31pub fn generic(input: TokenStream) -> TokenStream {
32 // Build the impl
33 let gen = impl_generic(input);
34 // println!("{}", gen);
35 // Return the generated impl
36 gen.into_token_stream().into()
37}
38
39/// Derives a Generic instance based on Field + HList for
40/// a given Struct (Tuple Structs not supported because they have
41/// no labels)
42///
43/// There *may* be problems if your field names contain certain characters.
44/// This can be solved by adding letters to the create_enums_for! macro invocation
45/// in frunk_core::labelled via a PR :)
46#[proc_macro_derive(LabelledGeneric)]
47pub fn labelled_generic(input: TokenStream) -> TokenStream {
48 // Build the impl
49 let gen = impl_labelled_generic(input);
50 // println!("{}", gen);
51 // Return the generated impl
52 gen.into_token_stream().into()
53}