[][src]Function flatdata::generate

pub fn generate(
    output_dir: &Path,
    schemas_path: &Path,
    generator: &Path
) -> Result<(), GeneratorError>

A helper function wrapping the flatdata generator.

Can be used to write build.rs build scripts, generating outputs either from a single schema, or recursively from a folder of schemas.

schemas_path can either be a single file, or a filder containing schemas. In both cases the function will only handle files with the .flatdata extension.

Generated files are in the same relative location, e.g.

schemas_path/
├────────────example_a/
│            ├─────────my_schema.flatdata
│            └─────────my_other_schema.flatdata
└────────────example_b.flatdata

results in

out_dir/
├───────example_a/
│       ├─────────my_schema.rs
│       └─────────my_other_schema.rs
└───────example_b.rs

Examples

build.rs

This example is not tested
use std::path::PathBuf;

fn main() {
    let out_path = PathBuf::from(std::env::var("OUT_DIR").unwrap());
    let test_cases_path = PathBuf::from("assets/schemas");
    let generator_path = PathBuf::from(std::env::var("GENERATOR_PATH").unwrap());

    match flatdata::generate(&out_path, &test_cases_path, &generator_path) {
       Err(e) => {
           eprintln!("{}", e);
           std::process::exit(1);
       }
       _ => (),
    }
}

my_schema.rs

This example is not tested
#![allow(dead_code)]

include!(concat!(env!("OUT_DIR"), "/path/to/my_schema.rs"));

// re-export if desired
pub use my_schema::*;