kutil_cli_macros/
lib.rs

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