Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
serdegen: Add --c-style-enums argument
Browse files Browse the repository at this point in the history
  • Loading branch information
mattico committed Nov 18, 2020
1 parent ec98362 commit d414c85
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions serde-generate/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ struct Options {
/// Optional package name (Python) or module path (Go) where to find Serde runtime dependencies.
#[structopt(long)]
serde_package_name: Option<String>,

/// Translate enums without variant data (c-style enums) into their equivalent in the target language.
#[structopt(long)]
c_style_enums: bool,
}

fn get_codegen_config<'a, I>(name: String, runtimes: I) -> CodeGeneratorConfig
fn get_codegen_config<'a, I>(name: String, runtimes: I, c_style_enums: bool) -> CodeGeneratorConfig
where
I: IntoIterator<Item = &'a Runtime>,
{
Expand All @@ -87,7 +91,9 @@ where
_ => (),
}
}
CodeGeneratorConfig::new(name).with_encodings(encodings)
CodeGeneratorConfig::new(name)
.with_encodings(encodings)
.with_c_style_enums(c_style_enums)
}

fn main() {
Expand All @@ -113,7 +119,7 @@ fn main() {
match options.target_source_dir {
None => {
if let Some((registry, name)) = named_registry_opt {
let config = get_codegen_config(name, &runtimes);
let config = get_codegen_config(name, &runtimes, options.c_style_enums);

let stdout = std::io::stdout();
let mut out = stdout.lock();
Expand Down Expand Up @@ -157,7 +163,7 @@ fn main() {
};

if let Some((registry, name)) = named_registry_opt {
let config = get_codegen_config(name, &runtimes);
let config = get_codegen_config(name, &runtimes, options.c_style_enums);
installer.install_module(&config, &registry).unwrap();
}

Expand Down

0 comments on commit d414c85

Please sign in to comment.