prost_unwrap_core/
lib.rs

1mod include;
2mod traverse;
3
4use include::Config;
5use proc_macro2::TokenStream;
6use quote::quote;
7use syn::parse2;
8
9use crate::traverse::*;
10
11/// The idea for this macro
12/// - Collect the config, that contains
13///     - this module path
14///     - original prost-generated structs module path
15///     - maybe structs and enums postfix
16///     - a prost-generated file that has a name of proto package (or specify)
17///     - a number of structs specs
18///         - struct fqn
19///         - array of required fields
20///         - array of additional attributes
21///     - a number of enums
22///         - enum fqn
23///         - array of additional attributes
24/// - For each linked file
25///     - Read and load the file into token streams
26///     - Traverse the AST, collecting
27///         - for each struct
28///             - struct fqn, AST, array of fields with field type
29///             - enum fqn, AST, array of variants with variant inner type if any
30/// - Traverse the collected data
31///     - validate that all configured structs and enums do exist
32///     - either
33///         - related types (option, hashmap, vec) are also configured
34///         - related types (option, hashmap, vec) are also added to the config
35///     - if conditions are not met, throw an error
36///         - unknown struct
37///         - unknwon field
38///         - related type is not configured
39/// - Assemble the module AST, including
40///     - error type
41///     - conversion functions (option, hashmap, vec) (TryFrom<O>, Into<O>)
42pub fn include(_item: TokenStream) -> TokenStream {
43    let config = parse2::<Config>(_item).unwrap();
44    let ast = traverse::copy_unwrapped(&config);
45    quote!(#ast)
46}