pub struct CodegenOptions { /* private fields */ }
Expand description
Options for the code generator.
This struct is a builder for the code generator options.
§Examples
CodegenOptions::new()
.spec("tighterror.yaml".to_owned())
.output("src/errors.rs".to_owned())
.codegen()?;
Implementations§
Source§impl CodegenOptions
impl CodegenOptions
Sourcepub fn spec(&mut self, spec: impl Into<PathBuf>) -> &mut Self
pub fn spec(&mut self, spec: impl Into<PathBuf>) -> &mut Self
Sets the specification file path.
If a value is not specified the default specification filenames are used in the following order:
- if the
yaml
feature is enabled the path DEFAULT_SPEC_PATH_YAML is used - if specification file is still not found and the
toml
feature is enabled the path DEFAULT_SPEC_PATH_TOML is used
§Examples
CodegenOptions::new().spec("tighterror.yaml");
Sourcepub fn spec_option(&mut self, spec: Option<PathBuf>) -> &mut Self
pub fn spec_option(&mut self, spec: Option<PathBuf>) -> &mut Self
Sets the specification file path option.
This method enhances spec
to set the specification
file path option. This is handy when one needs to
reset the option back to None
or has an Option<PathBuf>
parsed
from command line.
§Examples
CodegenOptions::new().spec_option(None);
CodegenOptions::new().spec_option(Some("tighterror.yaml".into()));
Sourcepub fn output(&mut self, output: impl Into<PathBuf>) -> &mut Self
pub fn output(&mut self, output: impl Into<PathBuf>) -> &mut Self
Sets the output path.
This can be either an absolute path, a relative path, or hyphen -
.
A relative path is relative to the location of the specification file.
If the path points to an existing directory the behavior depends on
separate files mode. If separate files is disabled the output is
written into file tighterror.rs
under the directory.
See separate_files
for the case when the mode
is enabled.
If the value is a hyphen -
, or output path is not set at all, the
output is written to stdout
.
A Some
value defined here overrides the MainObject::output
attribute
in the specification file.
§Examples
CodegenOptions::new().output("src/errors.rs");
Sourcepub fn output_option(&mut self, output: Option<PathBuf>) -> &mut Self
pub fn output_option(&mut self, output: Option<PathBuf>) -> &mut Self
Sets the output path option.
This method enhances output
to set the output path
option. This is handy when one needs to reset the option back to None
or has an Option<PathBuf>
parsed from command line.
§Examples
CodegenOptions::new().output_option(None);
CodegenOptions::new().output_option(Some("./src".into()));
Sourcepub fn test(&mut self, test: impl Into<Option<bool>>) -> &mut Self
pub fn test(&mut self, test: impl Into<Option<bool>>) -> &mut Self
Enables the unit test.
When enabled a module unit-test is included in the generated code.
In no_std
environments test cases that require std
are excluded.
§Examples
CodegenOptions::new().test(None);
CodegenOptions::new().test(true);
CodegenOptions::new().test(Some(false));
Sourcepub fn update(&mut self, update: impl Into<Option<bool>>) -> &mut Self
pub fn update(&mut self, update: impl Into<Option<bool>>) -> &mut Self
Enables the update mode.
If the value is true
and the output file already exists
it is not overwritten if the new content equals the existing one.
This option is useful to avoid recompilation of a crate, because
cargo
rebuilds a crate when one of the source file’s modification
time changes. When using the update mode the modification time
changes only when the file data changes, and recompilation is really
needed. Without update mode the output file is overwritten
unconditionally, even when the new data equals the existing one.
This may cause an unnecessary recompilation.
§Examples
CodegenOptions::new().update(None);
CodegenOptions::new().update(true);
CodegenOptions::new().update(Some(false));
Sourcepub fn separate_files(
&mut self,
separate_files: impl Into<Option<bool>>,
) -> &mut Self
pub fn separate_files( &mut self, separate_files: impl Into<Option<bool>>, ) -> &mut Self
Enables the separate files mode.
When enabled every module in specification is written to a separate
file. The output
option must point to an
existing directory. The module files, named after the modules
with addition of the .rs
suffix, are written under the directory.
For example, assuming output
equals ./src
and there
are two modules named errors
and internal_errors
, the modules will
be written to ./src/errors.rs
and ./src/internal_errors.rs
respectively.
If the output is written to stdout
the separate files mode is
implicitly disabled.
Trait Implementations§
Source§impl Clone for CodegenOptions
impl Clone for CodegenOptions
Source§fn clone(&self) -> CodegenOptions
fn clone(&self) -> CodegenOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more