architect_api_schema_builder/
code_gen.rs1use proc_macro2::TokenStream;
5use std::collections::HashSet;
6use tonic_build::{Attributes, Service};
7
8#[derive(Debug)]
10pub struct CodeGenBuilder {
11 emit_package: bool,
12 compile_well_known_types: bool,
13 attributes: Attributes,
14 build_transport: bool,
15 disable_comments: HashSet<String>,
16 use_arc_self: bool,
17 generate_default_stubs: bool,
18}
19
20impl CodeGenBuilder {
21 pub fn new() -> Self {
23 Default::default()
24 }
25
26 pub fn emit_package(&mut self, enable: bool) -> &mut Self {
28 self.emit_package = enable;
29 self
30 }
31
32 pub fn attributes(&mut self, attributes: Attributes) -> &mut Self {
36 self.attributes = attributes;
37 self
38 }
39
40 pub fn build_transport(&mut self, build_transport: bool) -> &mut Self {
46 self.build_transport = build_transport;
47 self
48 }
49
50 pub fn compile_well_known_types(&mut self, enable: bool) -> &mut Self {
53 self.compile_well_known_types = enable;
54 self
55 }
56
57 pub fn disable_comments(&mut self, disable_comments: HashSet<String>) -> &mut Self {
59 self.disable_comments = disable_comments;
60 self
61 }
62
63 pub fn use_arc_self(&mut self, enable: bool) -> &mut Self {
65 self.use_arc_self = enable;
66 self
67 }
68
69 pub fn generate_default_stubs(&mut self, generate_default_stubs: bool) -> &mut Self {
71 self.generate_default_stubs = generate_default_stubs;
72 self
73 }
74
75 pub fn generate_server_definition(
80 &self,
81 service: &impl Service,
82 rewrite_crate: &str,
83 proto_path: &str,
84 ) -> TokenStream {
85 crate::server::generate_definition(
86 service,
87 self.emit_package,
88 rewrite_crate,
89 proto_path,
90 self.compile_well_known_types,
91 &self.attributes,
92 &self.disable_comments,
93 self.use_arc_self,
94 self.generate_default_stubs,
95 )
96 }
97}
98
99impl Default for CodeGenBuilder {
100 fn default() -> Self {
101 Self {
102 emit_package: true,
103 compile_well_known_types: false,
104 attributes: Attributes::default(),
105 build_transport: true,
106 disable_comments: HashSet::default(),
107 use_arc_self: false,
108 generate_default_stubs: false,
109 }
110 }
111}