Weird behavior using Vec
gdetrez opened this issue · 3 comments
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.
After a bit more investigation, I now believe this is the same issue as #9: bits of the "old" config remain when storing the modified config. And if I switch to the git repo in Cargo.toml, the example works as expected.
I didn't notice the similarity at first because in my tests the config file remained syntactically valid.
any update on this issue?