diff options
author | David Tolnay <dtolnay@gmail.com> | 2020-11-01 17:02:07 -0800 |
---|---|---|
committer | David Tolnay <dtolnay@gmail.com> | 2020-11-01 17:31:56 -0800 |
commit | 92b7b6d5757bb9a80424cb60a2b87e09e52b04a8 (patch) | |
tree | 4c00f8681c8ef36d34a729a5c0ea416426aa5852 /gen/src/mod.rs | |
parent | ac7188c8717e7aeb1535e876682e5038dc0ffcc7 (diff) | |
download | cxx-92b7b6d5757bb9a80424cb60a2b87e09e52b04a8.tar.gz |
Condense creation of GeneratedCode
Diffstat (limited to 'gen/src/mod.rs')
-rw-r--r-- | gen/src/mod.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/gen/src/mod.rs b/gen/src/mod.rs index 554334ce..a4a159d2 100644 --- a/gen/src/mod.rs +++ b/gen/src/mod.rs @@ -134,16 +134,15 @@ pub(super) fn generate(syntax: File, opt: &Opt) -> Result<GeneratedCode> { // Some callers may wish to generate both header and implementation from the // same token stream to avoid parsing twice. Others only need to generate // one or the other. + let (mut header, mut implementation) = Default::default(); + if opt.gen_header { + header = write::gen(apis, types, opt, true); + } + if opt.gen_implementation { + implementation = write::gen(apis, types, opt, false); + } Ok(GeneratedCode { - header: if opt.gen_header { - write::gen(apis, types, opt, true) - } else { - Vec::new() - }, - implementation: if opt.gen_implementation { - write::gen(apis, types, opt, false) - } else { - Vec::new() - }, + header, + implementation, }) } |