pub struct SectionSetter<'a> { /* private fields */ }
Expand description
A setter which could be used to set key-value pair in a specified section
Implementations§
Source§impl<'a> SectionSetter<'a>
impl<'a> SectionSetter<'a>
Sourcepub fn set<'b, K, V>(
&'b mut self,
key: K,
value: V,
) -> &'b mut SectionSetter<'a>
pub fn set<'b, K, V>( &'b mut self, key: K, value: V, ) -> &'b mut SectionSetter<'a>
Set (replace) key-value pair in this section (all with the same name)
Examples found in repository?
examples/test.rs (line 9)
7fn main() {
8 let mut conf = Ini::new();
9 conf.with_section(None::<String>).set("encoding", "utf-8");
10 conf.with_section(Some("User"))
11 .set("name", "Raspberry树莓")
12 .set("value", "Pi");
13 conf.with_section(Some("Library"))
14 .set("name", "Sun Yat-sen U")
15 .set("location", "Guangzhou=world\x0ahahaha");
16
17 conf.section_mut(Some("Library")).unwrap().insert("seats", "42");
18
19 println!("---------------------------------------");
20 println!("Writing to file {:?}\n", CONF_FILE_NAME);
21 conf.write_to(&mut stdout()).unwrap();
22
23 conf.write_to_file(CONF_FILE_NAME).unwrap();
24
25 println!("----------------------------------------");
26 println!("Reading from file {:?}", CONF_FILE_NAME);
27 let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();
28
29 println!("Iterating");
30 let general_section_name = "__General__";
31 for (sec, prop) in i.iter() {
32 let section_name = sec.as_ref().unwrap_or(&general_section_name);
33 println!("-- Section: {:?} begins", section_name);
34 for (k, v) in prop.iter() {
35 println!("{}: {:?}", k, v);
36 }
37 }
38 println!();
39
40 let section = i.section(Some("User")).unwrap();
41 println!("name={}", section.get("name").unwrap());
42 println!("conf[User][name]={}", &i["User"]["name"]);
43 println!("General Section: {:?}", i.general_section());
44}
Sourcepub fn add<'b, K, V>(
&'b mut self,
key: K,
value: V,
) -> &'b mut SectionSetter<'a>
pub fn add<'b, K, V>( &'b mut self, key: K, value: V, ) -> &'b mut SectionSetter<'a>
Add (append) key-value pair in this section
Sourcepub fn delete<'b, K>(&'b mut self, key: &K) -> &'b mut SectionSetter<'a>
pub fn delete<'b, K>(&'b mut self, key: &K) -> &'b mut SectionSetter<'a>
Delete the first entry in this section with key
Auto Trait Implementations§
impl<'a> Freeze for SectionSetter<'a>
impl<'a> RefUnwindSafe for SectionSetter<'a>
impl<'a> Send for SectionSetter<'a>
impl<'a> Sync for SectionSetter<'a>
impl<'a> Unpin for SectionSetter<'a>
impl<'a> !UnwindSafe for SectionSetter<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more