use orion_conf::{ConfigIO, JsonIO};
use std::path::Path;
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq)]
struct TestConfig {
name: String,
value: i32,
enabled: bool,
}
fn main() {
let path = Path::new("test_config.json");
let config = TestConfig {
name: "test_app".to_string(),
value: 42,
enabled: true,
};
match config.save_json(path) {
Ok(()) => println!("Successfully saved JSON config"),
Err(e) => println!("Failed to save JSON config: {}", e),
}
match TestConfig::load_json(path) {
Ok(loaded_config) => {
println!("Successfully loaded JSON config: {:?}", loaded_config);
assert_eq!(config, loaded_config);
println!("JSON round-trip test passed!");
}
Err(e) => println!("Failed to load JSON config: {}", e),
}
match TestConfig::load_conf(path) {
Ok(loaded_config) => {
println!(
"Successfully loaded config using ConfigIO: {:?}",
loaded_config
);
assert_eq!(config, loaded_config);
println!("ConfigIO with JSON feature test passed!");
}
Err(e) => println!("Failed to load config using ConfigIO: {}", e),
}
let _ = std::fs::remove_file(path);
}