1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use std::collections::HashSet;
use proc_macro2::TokenStream;
use crate::{Attributes, Service};
#[derive(Debug)]
pub struct CodeGenBuilder {
emit_package: bool,
compile_well_known_types: bool,
attributes: Attributes,
build_transport: bool,
disable_comments: HashSet<String>,
}
impl CodeGenBuilder {
pub fn new() -> Self {
Default::default()
}
pub fn emit_package(&mut self, enable: bool) -> &mut Self {
self.emit_package = enable;
self
}
pub fn attributes(&mut self, attributes: Attributes) -> &mut Self {
self.attributes = attributes;
self
}
pub fn build_transport(&mut self, build_transport: bool) -> &mut Self {
self.build_transport = build_transport;
self
}
pub fn compile_well_known_types(&mut self, enable: bool) -> &mut Self {
self.compile_well_known_types = enable;
self
}
pub fn disable_comments(&mut self, disable_comments: HashSet<String>) -> &mut Self {
self.disable_comments = disable_comments;
self
}
pub fn generate_client(&self, service: &impl Service, proto_path: &str) -> TokenStream {
crate::client::generate_internal(
service,
self.emit_package,
proto_path,
self.compile_well_known_types,
self.build_transport,
&self.attributes,
&self.disable_comments,
)
}
pub fn generate_server(&self, service: &impl Service, proto_path: &str) -> TokenStream {
crate::server::generate_internal(
service,
self.emit_package,
proto_path,
self.compile_well_known_types,
&self.attributes,
&self.disable_comments,
)
}
}
impl Default for CodeGenBuilder {
fn default() -> Self {
Self {
emit_package: true,
compile_well_known_types: false,
attributes: Attributes::default(),
build_transport: true,
disable_comments: HashSet::default(),
}
}
}