protobuf_codegen_no_elision/
customize.rs1use protobuf::rustproto;
2use protobuf::descriptor::FieldOptions;
3use protobuf::descriptor::MessageOptions;
4use protobuf::descriptor::FileOptions;
5
6
7#[derive(Default, Debug, Clone)]
9pub struct Customize {
10 pub expose_oneof: Option<bool>,
12 pub expose_fields: Option<bool>,
14 pub generate_accessors: Option<bool>,
16 pub carllerche_bytes_for_bytes: Option<bool>,
18 pub carllerche_bytes_for_string: Option<bool>,
20}
21
22impl Customize {
23 pub fn update_with(&mut self, that: &Customize) {
25 if let Some(v) = that.expose_oneof {
26 self.expose_oneof = Some(v);
27 }
28 if let Some(v) = that.expose_fields {
29 self.expose_fields = Some(v);
30 }
31 if let Some(v) = that.generate_accessors {
32 self.generate_accessors = Some(v);
33 }
34 if let Some(v) = that.carllerche_bytes_for_bytes {
35 self.carllerche_bytes_for_bytes = Some(v);
36 }
37 if let Some(v) = that.carllerche_bytes_for_string {
38 self.carllerche_bytes_for_string = Some(v);
39 }
40 }
41
42 pub fn set_defaults_from(&mut self, other: &Customize) {
44 let mut tmp = other.clone();
45 tmp.update_with(self);
46 *self = tmp;
47 }
48}
49
50
51pub fn customize_from_rustproto_for_message(source: &MessageOptions) -> Customize {
52 let expose_oneof = rustproto::exts::expose_oneof.get(source);
53 let expose_fields = rustproto::exts::expose_fields.get(source);
54 let generate_accessors = rustproto::exts::generate_accessors.get(source);
55 let carllerche_bytes_for_bytes = rustproto::exts::carllerche_bytes_for_bytes.get(source);
56 let carllerche_bytes_for_string = rustproto::exts::carllerche_bytes_for_string.get(source);
57 Customize {
58 expose_oneof,
59 expose_fields,
60 generate_accessors,
61 carllerche_bytes_for_bytes,
62 carllerche_bytes_for_string,
63 }
64}
65
66pub fn customize_from_rustproto_for_field(source: &FieldOptions) -> Customize {
67 let expose_oneof = None;
68 let expose_fields = rustproto::exts::expose_fields_field.get(source);
69 let generate_accessors = rustproto::exts::generate_accessors_field.get(source);
70 let carllerche_bytes_for_bytes = rustproto::exts::carllerche_bytes_for_bytes_field.get(source);
71 let carllerche_bytes_for_string = rustproto::exts::carllerche_bytes_for_string_field.get(source);
72 Customize {
73 expose_oneof,
74 expose_fields,
75 generate_accessors,
76 carllerche_bytes_for_bytes,
77 carllerche_bytes_for_string,
78 }
79}
80
81pub fn customize_from_rustproto_for_file(source: &FileOptions) -> Customize {
82 let expose_oneof = rustproto::exts::expose_oneof_all.get(source);
83 let expose_fields = rustproto::exts::expose_fields_all.get(source);
84 let generate_accessors = rustproto::exts::generate_accessors_all.get(source);
85 let carllerche_bytes_for_bytes = rustproto::exts::carllerche_bytes_for_bytes_all.get(source);
86 let carllerche_bytes_for_string = rustproto::exts::carllerche_bytes_for_string_all.get(source);
87 Customize {
88 expose_oneof,
89 expose_fields,
90 generate_accessors,
91 carllerche_bytes_for_bytes,
92 carllerche_bytes_for_string,
93 }
94}