camo_derive/
lib.rs

1#![warn(missing_docs)]
2
3//! This crate provides `camo`'s derive macro.
4//!
5//! ```edition2021
6//! use camo_derive::Camo;
7//!
8//! #[derive(Camo)]
9//! struct Foo {
10//!     bar: i32,
11//! }
12//!
13//! let ast = Foo::camo();
14//! // ...
15//! ```
16
17mod ast;
18mod derive;
19
20use derive::derive;
21use proc_macro::TokenStream;
22use syn::{parse_macro_input, DeriveInput};
23
24/// Derives an implementation of the `Camo` trait.
25///
26/// The macro understands the `serde`-attributes `rename`, `rename_all`,
27/// `tag`, and `content`, both on the container type and on enum variants.
28#[proc_macro_derive(Camo, attributes(serde))]
29pub fn derive_macro_impl(input: TokenStream) -> TokenStream {
30    let input = parse_macro_input!(input as DeriveInput);
31    let output = derive(input);
32    TokenStream::from(output)
33}