Module preserves_schema::compiler

source ·
Expand description

Implementation of the Schema-to-Rust compiler; this is the core of the preserves-schema-rs program.

See the documentation for preserves-schema-rs for examples of how to use the compiler programmatically from a build.rs script, but very briefly, use preserves-schemac to generate a metaschema instance *.prb file, and then put something like this in build.rs:

use preserves_schema::compiler::*;

const PATH_TO_PRB_FILE: &'static str = "your-metaschema-instance-file.prb";

fn main() -> Result<(), std::io::Error> {
    let buildroot = std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap());

    let mut gen_dir = buildroot.clone();
    gen_dir.push("src/schemas");
    let mut c = CompilerConfig::new("crate::schemas".to_owned());

    let inputs = expand_inputs(&vec![PATH_TO_PRB_FILE.to_owned()])?;
    c.load_schemas_and_bundles(&inputs, &vec![])?;
    compile(&c, &mut CodeCollector::files(gen_dir))
}

plus something like this in your lib.rs or main program:

pub mod schemas {
    include!(concat!(env!("OUT_DIR"), "/src/schemas/mod.rs"));
}

Modules§

Structs§

Enums§

Traits§

  • Implement this trait to extend the compiler with custom code generation support. The main code generators are also implemented as plugins.

Functions§

Type Aliases§

  • Names a Schema module within a (collection of) Schema bundle(s).