Struct CodegenOptions

Source
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

Source

pub fn new() -> Self

Creates a new options object with default values.

Source

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:

§Examples
CodegenOptions::new().spec("tighterror.yaml");
Source

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()));
Source

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");
Source

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()));
Source

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));
Source

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));
Source

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.

Source

pub fn codegen(&self) -> Result<(), TbError>

Invokes the code generator main function using these options.

See the struct documentation for a full example.

Trait Implementations§

Source§

impl Clone for CodegenOptions

Source§

fn clone(&self) -> CodegenOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodegenOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CodegenOptions

Source§

fn default() -> CodegenOptions

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.