We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Result is None when test.toml is blank. I wish to get as below, how can I do it?
Some( Test { sub: Some( [ Data { id: 2, name: "3", }, Data { id: 4, name: "5", }, ], ), }, )
my code is here:
testconfig.rs:
use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct Data { pub id: usize, pub name: String, } impl Default for Data { fn default() -> Self { Self { id: 1, name: "test1".to_string(), } } } #[derive(Debug, Serialize, Deserialize)] pub struct Test { #[allow(dead_code)] pub sub: Option<Vec<Data>>, } impl Default for Test { fn default() -> Self { Self { sub: Some(vec![Data{id:2,name: "3".to_string()}, Data{id:4, name: "5".to_string()}]) } } } #[derive(Debug, Serialize, Deserialize)] pub struct TestGlobalConfig { #[allow(dead_code)] pub test: Option<Test>, } impl Default for TestGlobalConfig { fn default() -> Self { Self { test: Some(Test::default()) } } }
main.rs:
use std::sync::RwLock; pub mod testconfig; use crate::testconfig::TestGlobalConfig; lazy_static::lazy_static! { static ref GLOBAL: RwLock<TestGlobalConfig> ={ let path = concat!(env!("CARGO_MANIFEST_DIR"),"/test.toml"); if let Ok(global_config) = confy::load_path::<TestGlobalConfig>(path) { RwLock::new(global_config) } else { panic!("load config file {path:?} error!"); } }; } fn main() { let binding = GLOBAL.read().unwrap(); let settings = &binding.test; println!("{:#?}", settings); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Result is None when test.toml is blank. I wish to get as below, how can I do it?
my code is here:
testconfig.rs:
main.rs:
The text was updated successfully, but these errors were encountered: