valuable_derive/lib.rs
1#![warn(rust_2018_idioms, unreachable_pub)]
2
3#[macro_use]
4mod error;
5
6mod attr;
7mod expand;
8
9use proc_macro::TokenStream;
10use syn::parse_macro_input;
11
12/// Derive a `Valuable` implementation for a struct or enum.
13///
14/// # Attributes
15///
16/// ## `#[valuable(rename = "...")]`
17///
18/// Use the given name instead of its Rust name.
19///
20/// ## `#[valuable(transparent)]`
21///
22/// Delegate the trait implementation to the field.
23///
24/// This attribute can only be used on a struct that has a single field.
25///
26/// ## `#[valuable(skip)]`
27///
28/// Skip the field.
29///
30/// # Examples
31///
32/// ```
33/// use valuable::Valuable;
34///
35/// #[derive(Valuable)]
36/// struct HelloWorld {
37/// message: Message,
38/// }
39///
40/// #[derive(Valuable)]
41/// enum Message {
42/// HelloWorld,
43/// Custom(String),
44/// }
45/// ```
46#[proc_macro_derive(Valuable, attributes(valuable))]
47pub fn derive_valuable(input: TokenStream) -> TokenStream {
48 let mut input = parse_macro_input!(input as syn::DeriveInput);
49 expand::derive_valuable(&mut input).into()
50}