depiction_macros/
lib.rs

1// https://stackoverflow.com/a/61417700
2#![cfg_attr(docsrs, feature(doc_cfg))]
3#![warn(missing_docs)]
4
5/*!
6A supercharged version of Rust's `Debug` trait.
7
8For more information and usage examples see the
9[home page](https://github.com/tliron/depiction).
10*/
11
12mod derive_depict;
13
14use derive_depict::*;
15
16// See: https://petanode.com/posts/rust-proc-macro/
17
18/// Procedural macro for `#[derive(Depict)]`.
19#[proc_macro_derive(Depict, attributes(depict))]
20pub fn derive_depict(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
21    let mut input: syn::DeriveInput = syn::parse_macro_input!(input);
22
23    match input.data {
24        syn::Data::Struct(_) => StructGenerator::generate(&mut input),
25
26        syn::Data::Enum(_) => EnumGenerator::generate(&mut input),
27
28        _ => Err(syn::Error::new(input.ident.span(), "`Depict`: not a struct")),
29    }
30    .unwrap_or_else(|e| e.to_compile_error())
31    .into()
32}