Created
February 16, 2020 01:27
-
-
Save NBZ4live/329e4a3bb24d2785e3d7a247a233d644 to your computer and use it in GitHub Desktop.
Rust config_struct crate build script with check for the existence of the config file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use config_struct::{Error, StructOptions}; | |
use std::fs; | |
const CONFIG_FILE_DST: &str = "src/config.rs"; | |
fn main() -> Result<(), Error> { | |
println!("cargo:rerun-if-changed=build.rs"); | |
println!("cargo:rerun-if-changed=config.toml"); | |
let mut config_file_src = "config.toml"; | |
let metadata = fs::metadata(config_file_src); | |
if metadata.is_err() || !metadata.unwrap().is_file() { | |
println!("cargo:warning={} not found!", config_file_src); | |
config_file_src = "config-example.toml"; | |
println!("cargo:warning=Using {} instead!", config_file_src); | |
} | |
config_struct::create_config( | |
config_file_src, | |
CONFIG_FILE_DST, | |
&StructOptions::default() | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment