diff options
Diffstat (limited to 'src/customize.rs')
-rw-r--r-- | src/customize.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/customize.rs b/src/customize.rs index f8e73aa..b3415ab 100644 --- a/src/customize.rs +++ b/src/customize.rs @@ -1,3 +1,4 @@ +use protobuf::descriptor::EnumOptions; use protobuf::descriptor::FieldOptions; use protobuf::descriptor::FileOptions; use protobuf::descriptor::MessageOptions; @@ -20,6 +21,8 @@ pub struct Customize { pub serde_derive: Option<bool>, /// When `serde_derive` is set, serde annotations will be guarded with `#[cfg(cfg, ...)]`. pub serde_derive_cfg: Option<String>, + /// When `serde_derive` is set, use attribute rename_all + pub serde_rename_all: Option<String>, /// Enable lite runtime pub lite_runtime: Option<bool>, /// Generate `mod.rs` in the output directory. @@ -71,6 +74,9 @@ impl Customize { if let Some(ref v) = that.serde_derive_cfg { self.serde_derive_cfg = Some(v.clone()); } + if let Some(ref v) = that.serde_rename_all { + self.serde_rename_all = Some(v.clone()); + } if let Some(v) = that.lite_runtime { self.lite_runtime = Some(v); } @@ -120,6 +126,8 @@ impl Customize { r.serde_derive = Some(parse_bool(v)?); } else if n == "serde_derive_cfg" { r.serde_derive_cfg = Some(v.to_owned()); + } else if n == "serde_rename_all" { + r.serde_rename_all = Some(v.to_owned()); } else if n == "lite_runtime" { r.lite_runtime = Some(parse_bool(v)?); } else if n == "gen_mod_rs" { @@ -147,6 +155,7 @@ pub fn customize_from_rustproto_for_message(source: &MessageOptions) -> Customiz let lite_runtime = None; let gen_mod_rs = None; let inside_protobuf = None; + let serde_rename_all = None; Customize { expose_oneof, expose_fields, @@ -155,6 +164,7 @@ pub fn customize_from_rustproto_for_message(source: &MessageOptions) -> Customiz carllerche_bytes_for_string, serde_derive, serde_derive_cfg, + serde_rename_all, lite_runtime, gen_mod_rs, inside_protobuf, @@ -162,6 +172,13 @@ pub fn customize_from_rustproto_for_message(source: &MessageOptions) -> Customiz } } +pub fn customize_from_rustproto_for_enum(source: &EnumOptions) -> Customize { + let serde_rename_all = rustproto::exts::serde_rename_all.get(source); + let mut r = Customize::default(); + r.serde_rename_all = serde_rename_all; + return r; +} + pub fn customize_from_rustproto_for_field(source: &FieldOptions) -> Customize { let expose_oneof = None; let expose_fields = rustproto::exts::expose_fields_field.get(source); @@ -169,6 +186,7 @@ pub fn customize_from_rustproto_for_field(source: &FieldOptions) -> Customize { let carllerche_bytes_for_bytes = rustproto::exts::carllerche_bytes_for_bytes_field.get(source); let carllerche_bytes_for_string = rustproto::exts::carllerche_bytes_for_string_field.get(source); + let serde_rename_all = None; let serde_derive = None; let serde_derive_cfg = None; let lite_runtime = None; @@ -182,6 +200,7 @@ pub fn customize_from_rustproto_for_field(source: &FieldOptions) -> Customize { carllerche_bytes_for_string, serde_derive, serde_derive_cfg, + serde_rename_all, lite_runtime, gen_mod_rs, inside_protobuf, @@ -200,6 +219,7 @@ pub fn customize_from_rustproto_for_file(source: &FileOptions) -> Customize { let lite_runtime = rustproto::exts::lite_runtime_all.get(source); let gen_mod_rs = None; let inside_protobuf = None; + let serde_rename_all = None; Customize { expose_oneof, expose_fields, @@ -208,6 +228,7 @@ pub fn customize_from_rustproto_for_file(source: &FileOptions) -> Customize { carllerche_bytes_for_string, serde_derive, serde_derive_cfg, + serde_rename_all, lite_runtime, inside_protobuf, gen_mod_rs, |