Weird behavior using Vec
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start with the provided minimal example and trace the confy::load and confy::store entry points while reproducing the Vec persistence behavior. Compare the loaded default values with the TOML output; done means removing items persists correctly and the distinct default items are not duplicated.
Written by the indexing model from the issue text.
Description
I'm using confy 0.3.1, and it seems that I am unable to remove items from a vec in my config (adding items works fine). But when I was trying to build a simple example to demonstrate the issue, I found a very confusing one.
Here's my code:
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct MyItem {
name: String,
}
#[derive(Debug, Serialize, Deserialize)]
struct MyConfig {
items: Vec<MyItem>,
}
/// `MyConfig` implements `Default`
impl ::std::default::Default for MyConfig {
fn default() -> Self {
Self {
items: vec![MyItem { name: "foo".into() }, MyItem { name: "bar".into() }],
}
}
}
fn main() -> Result<(), ::std::io::Error> {
let mut cfg: MyConfig = confy::load("foobar")?;
println!("{:?}", cfg);
cfg.items.remove(0);
println!("{:?}", cfg);
confy::store("foobar", cfg)?;
Ok(())
}
This is what I get in the config file after running it (any number of times):
[[items]]
name = 'bar'
[[items]]
name = 'bar'
I expected one item after the first run and zero after subsequent runs. And the default vec has two different items (foo and bar) whereas the toml file have the same item twice.
- 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 3/5 1-2 days Newbie friendliness 25/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
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