concision_derive/
lib.rs

1/*
2   Appellation: concision-derive <library>
3   Contrib: FL03 <jo3mccain@icloud.com>
4*/
5//! Derive macros for the concision framework.
6//!
7//! ## Overview
8//!
9//!
10#![crate_type = "proc-macro"]
11
12extern crate proc_macro;
13extern crate quote;
14extern crate syn;
15
16pub(crate) mod ast;
17#[allow(dead_code)]
18pub(crate) mod attrs;
19pub(crate) mod impls;
20pub(crate) mod utils;
21
22use proc_macro::TokenStream;
23use syn::{DeriveInput, parse_macro_input};
24
25/// The [`Configuration`] derive macro generates configuration-related code for a given struct,
26/// streamlining the process of creating compatible configuration spaces within the concision
27/// framework.
28#[proc_macro_derive(Configuration, attributes(config))]
29pub fn configuration(input: TokenStream) -> TokenStream {
30    // Parse the input tokens into a syntax tree
31    let input = parse_macro_input!(input as DeriveInput);
32
33    let res = impls::impl_config(&input);
34
35    // Return the generated code as a TokenStream
36    res.into()
37}
38
39/// This macro generates a parameter struct and an enum of parameter keys.
40#[proc_macro_derive(Keyed, attributes(keys))]
41pub fn keyed(input: TokenStream) -> TokenStream {
42    // Parse the input tokens into a syntax tree
43    let input = parse_macro_input!(input as DeriveInput);
44
45    let res = impls::impl_keys(&input);
46
47    // Return the generated code as a TokenStream
48    res.into()
49}