valust_derive/
lib.rs

1//! Derive macro implementation for `Valust`.
2#![doc = include_str!("../README.md")]
3
4// mod config;
5// mod parse;
6mod cmd;
7mod syntax;
8mod utils;
9
10use proc_macro::TokenStream;
11use syn::{DeriveInput, parse_macro_input};
12use syntax::structure::Structure;
13
14// const FIELD_ATTRS: &[&str] = &["valid", "trans", "forward", "display"];
15// const STRUCT_ATTRS: &[&str] = &["pre", "post", "rename", "forward_derive"];
16
17/// Main entry point for the `Valust` macro.
18///
19/// For full documentation, see the crates's README file.
20#[proc_macro_derive(
21    Valust,
22    attributes(valid, trans, forward, forward_attr, pre, post, rename, forward_derive)
23)]
24pub fn valust_derive(item: TokenStream) -> TokenStream {
25    let input = parse_macro_input!(item as DeriveInput);
26
27    let data = match Structure::from_input(input) {
28        Ok(t) => t,
29        Err(e) => return e.to_compile_error().into(),
30    };
31    let expanded = match data.gen_validate_impl() {
32        Ok(t) => t,
33        Err(e) => return e.to_compile_error().into(),
34    };
35
36    expanded.into()
37}