Function varlink_generator::cargo_build_tosource_options[][src]

pub fn cargo_build_tosource_options<T: AsRef<Path> + ?Sized>(
    input_path: &T,
    rustfmt: bool,
    options: &GeneratorOptions
)

cargo build helper function

cargo_build_tosource_options is used in a build.rs program to build the rust code from a varlink interface definition. This function saves the rust code in the same directory as the varlink file. The name is the name of the varlink file and “.” replaced with “_” and of course ending with “.rs”.

Use this, if you are using an IDE with code completion, as most cannot cope with include!(concat!(env!("OUT_DIR"), "<varlink_file>"));

Set rustfmt to true, if you want the generator to run rustfmt on the generated code. This might be good practice to avoid large changes after a global cargo fmt run.

Errors are emitted to stderr and terminate the process.

Examples

extern crate varlink_generator;

fn main() {
    varlink_generator::cargo_build_tosource_options(
        "src/org.example.ping.varlink",
        true,
        &varlink_generator::GeneratorOptions {
            int_type: Some("i128"),
            ..Default::default()
        },
    );
}