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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use prost_types::source_code_info::Location;
use prost_types;
#[derive(Debug)]
pub struct Comments {
pub leading_detached: Vec<Vec<String>>,
pub leading: Vec<String>,
pub trailing: Vec<String>,
}
impl Comments {
pub(crate) fn from_location(location: &Location) -> Comments {
fn get_lines<S>(comments: S) -> Vec<String> where S: AsRef<str> {
comments.as_ref().lines().map(str::to_owned).collect()
}
let leading_detached = location.leading_detached_comments.iter().map(get_lines).collect();
let leading = location.leading_comments.as_ref().map_or(Vec::new(), get_lines);
let trailing = location.trailing_comments.as_ref().map_or(Vec::new(), get_lines);
Comments {
leading_detached: leading_detached,
leading: leading,
trailing: trailing,
}
}
pub fn append_with_indent(&self, indent_level: u8, buf: &mut String) {
for detached_block in &self.leading_detached {
for line in detached_block {
for _ in 0..indent_level {
buf.push_str(" ");
}
buf.push_str("//");
buf.push_str(line);
buf.push_str("\n");
}
buf.push_str("\n");
}
for line in &self.leading {
for _ in 0..indent_level {
buf.push_str(" ");
}
buf.push_str("///");
buf.push_str(line);
buf.push_str("\n");
}
if !self.leading.is_empty() && !self.trailing.is_empty() {
for _ in 0..indent_level {
buf.push_str(" ");
}
buf.push_str("///\n");
}
for line in &self.trailing {
for _ in 0..indent_level {
buf.push_str(" ");
}
buf.push_str("///");
buf.push_str(line);
buf.push_str("\n");
}
}
}
#[derive(Debug)]
pub struct Service {
pub name: String,
pub proto_name: String,
pub package: String,
pub comments: Comments,
pub methods: Vec<Method>,
pub options: prost_types::ServiceOptions,
}
#[derive(Debug)]
pub struct Method {
pub name: String,
pub proto_name: String,
pub comments: Comments,
pub input_type: String,
pub output_type: String,
pub input_proto_type: String,
pub output_proto_type: String,
pub options: prost_types::MethodOptions,
pub client_streaming: bool,
pub server_streaming: bool,
}