Expose function for reading the configuration
parent
fac04fd6d4
commit
df91226979
11
src/lib.rs
11
src/lib.rs
|
@ -10,10 +10,15 @@ mod rust;
|
|||
mod util;
|
||||
|
||||
use std::error::Error;
|
||||
use std::fmt::Display;
|
||||
use std::path::Path;
|
||||
use configuration::Config;
|
||||
|
||||
pub fn read_config_file<P: AsRef<Path>>(
|
||||
config_file: P,
|
||||
) -> Result<Config, Box<Error>> {
|
||||
configuration::parse(config_file)
|
||||
}
|
||||
|
||||
pub fn generate_bindings(config: &Config) -> Result<(), Box<Error>> {
|
||||
cpp::write_header(config)?;
|
||||
cpp::write_cpp(config)?;
|
||||
|
@ -22,11 +27,11 @@ pub fn generate_bindings(config: &Config) -> Result<(), Box<Error>> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn generate_bindings_from_config_file<P: AsRef<Path> + Display>(
|
||||
pub fn generate_bindings_from_config_file<P: AsRef<Path>>(
|
||||
config_file: P,
|
||||
overwrite_implementation: bool,
|
||||
) -> Result<(), Box<Error>> {
|
||||
let mut config = configuration::parse(config_file)?;
|
||||
let mut config = read_config_file(config_file)?;
|
||||
if overwrite_implementation {
|
||||
config.overwrite_implementation = true;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ pub fn write_if_different<P: AsRef<Path>>(path: P, contents: &[u8]) -> Result<()
|
|||
if old_contents.map(|c| c == contents).unwrap_or(false) {
|
||||
Ok(())
|
||||
} else {
|
||||
let _ = fs::create_dir_all(path.as_ref().parent().unwrap());
|
||||
fs::write(path, contents)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue