zonyitoo / rust-ini

INI file parser in Rust
MIT License
305 stars 79 forks source link

Restrict lifetimes of SectionSetter methods #135

Closed rikyborg closed 3 months ago

rikyborg commented 3 months ago

Fixes #134

Allow both for chaining calls to set/add/delete, and for separate calls of those methods on the same SectionSetter variable:

        let mut ini = Ini::new();
        let mut section_setter = ini.with_section(Some("section"));

        // chained set() calls
        section_setter.set("a", "1").set("b", "2");
        // separate set() calls
        section_setter.set("c", "3");

The last call would previously raise a compiler error because section_setter was still mutably borrowed until it went out of scope.

Also, change get() method to take &self rather than &mut self.