1use darling::FromDeriveInput;
2use proc_macro2::TokenStream;
3use syn::DeriveInput;
4mod attributes;
5mod enum_codegen;
6mod prost_ext;
7mod proto_conv;
8mod struct_codegen;
9pub mod traits;
10mod utils;
11
12use self::attributes::{
13 Direction,
14 FromProtoInfo,
15 IntoProtoInfo,
16 ProstMessageInto,
17 ProtoInfo,
18};
19
20pub fn derive_into_proto(input: DeriveInput) -> TokenStream {
21 let into_info = match IntoProtoInfo::from_derive_input(&input) {
22 | Ok(info) => info,
23 | Err(e) => {
24 return e.write_errors();
25 }
26 };
27 derive_proto(Direction::IntoProto(into_info), input)
28}
29
30pub fn derive_from_proto(input: DeriveInput) -> TokenStream {
31 let from_info = match FromProtoInfo::from_derive_input(&input) {
32 | Ok(info) => info,
33 | Err(e) => {
34 return e.write_errors();
35 }
36 };
37 derive_proto(Direction::FromProto(from_info), input)
38}
39
40fn derive_proto(
41 direction: Direction<FromProtoInfo, IntoProtoInfo>,
42 input: DeriveInput,
43) -> TokenStream {
44 let tokens = ProtoInfo::from_derive_input(&input)
45 .and_then(|info| proto_conv::expand_proto_conv(direction, info, input));
46
47 match tokens {
48 | Ok(tokens) => tokens,
49 | Err(e) => e.write_errors(),
50 }
51}
52
53pub fn derive_prost_message_ext(input: DeriveInput) -> TokenStream {
54 let tokens = ProstMessageInto::from_derive_input(&input)
55 .and_then(|info| prost_ext::expand_prost_ext(info, input));
56
57 match tokens {
58 | Ok(tokens) => tokens,
59 | Err(e) => e.write_errors(),
60 }
61}