airone_derive/
lib.rs

1//  ------------------------------------------------------------------
2//  Airone
3//  is a Rust library which provides a simple in-memory,
4//  write-on-update database that is persisted
5//  to an append-only transaction file.
6//
7//  Copyright © 2022,2023,2024 Massimo Gismondi
8//
9//  This file is part of Airone.
10//  Airone is free software: you can redistribute it and/or
11//  modify it under the terms of the GNU Affero General Public License
12//  as published by the Free Software Foundation, either version 3
13//  of the License, or (at your option) any later version.
14//
15//  This program is distributed in the hope that it will be useful,
16//  but WITHOUT ANY WARRANTY; without even the implied warranty of
17//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18//  GNU General Public License for more details.
19
20//  You should have received a copy of the GNU Affero General Public License
21//  along with this program. If not, see <https://www.gnu.org/licenses/>.
22//  ------------------------------------------------------------------
23#![forbid(unsafe_code)]
24
25use proc_macro::TokenStream;
26use syn::{parse_macro_input, DeriveInput};
27use quote::quote;
28
29mod gettersetter;
30use gettersetter::build_getset;
31
32mod serde;
33use serde::build_serde;
34
35
36/// A macro needed to generate methods to use your
37/// struct with [AironeDb](https://gitlab.com/MassiminoilTrace/airone)
38#[proc_macro_derive(AironeDbDerive)]
39pub fn getters(input: TokenStream) -> TokenStream {
40
41    let input = parse_macro_input!(input as DeriveInput);
42
43    let crate_name = quote!{airone};
44
45    let serde_data = build_serde(&input, crate_name.clone());
46    let access_functions = build_getset(input.clone());
47
48    quote!{
49        #serde_data
50        #access_functions
51    }.into()
52}