Get part result from default()
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
Research direction
Start with the reproducer in testconfig.rs and main.rs, especially the blank test.toml and the confy::load_path:: call. Verify the loaded value and compare it with the Default implementations; done should mean the expected behavior for an empty file is clearly established and covered by a focused test or documentation.
Written by the indexing model from the issue text.
Description
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);
}
- Dominant language
- Rust
- Stars
- 1k
- Forks
- 78
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rust-cli/confy
-
Difficulty 2/5 1-3 hours Newbie friendliness 50/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100