Skip to main content

generate_files

Function generate_files 

Source
pub fn generate_files(config: &CodegenOptions) -> Result<(), Error>
Expand description

Generate Rust source files from Varlink interface files.

This function reads Varlink interface definition files from config.files, parses them, generates corresponding Rust code, and handles output based on the configuration.

§Behavior

  • If config.output is specified: Generates a single file with all interfaces combined.
  • If config.multiple_files is true: Generates separate .rs files for each interface in the current working directory. The output filename is derived from the interface name (dots replaced with underscores and converted to lowercase).
  • Otherwise: Writes the generated code to stdout.

§Arguments

  • config - Code generation options containing input files, output configuration, and formatting options.

§Returns

Returns Ok(()) on successful code generation and output.

§Errors

This function will return an error if:

§Examples

use std::path::PathBuf;
use zlink_codegen::CodegenOptions;

let config = CodegenOptions {
    files: vec![PathBuf::from("interface.varlink")],
    output: Some(PathBuf::from("generated.rs")),
    rustfmt: true,
    ..Default::default()
};
zlink_codegen::generate_files(&config).expect("Failed to generate code");