rust-ini icon indicating copy to clipboard operation
rust-ini copied to clipboard

Insert Duplicate Section?

Open theonewolf opened this issue 5 years ago • 5 comments

I am testing support for duplicate sections, and I can not figure out how to add a new section with the same name as an old section. I actually don't think it's exposed in your API currently.

Parsing duplicate sections from files works fine, but adding same named sections does not (using with_section). I recommend adding a new method for instantiating sections, or a boolean on with_section that flags creation of a section--not retrieval / insertion into a pre-existing section.

@zonyitoo very close to having full support for #49! Instead of re-opening it, I figured I'd file another bug report.

theonewolf avatar May 02 '20 19:05 theonewolf

Hmm, I didn't add that because with_section was defined for insert or modify the section that is already existed.

Consider using the entry API:

let mut ini = Ini::new();
match ini.entry(Some("KeyDuplicated")) {
    SectionEntry::Vacant(mut vac) => {
    }
    SectionEntry::Occupied(mut occ) => {
        // Append a new section with the same name
        occ.append(...);
    }
}

zonyitoo avatar May 03 '20 11:05 zonyitoo

@zonyitoo thanks for the tip, I'll let you know if it covers my use case and close this out. Yes, with your API and how things work it did feel odd adding in what I described.

I really wish systemd used a standard configuration format vs rolling their own.

theonewolf avatar May 03 '20 12:05 theonewolf