Struct SectionSetter

Source
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>

Source

pub fn set<'b, K, V>( &'b mut self, key: K, value: V, ) -> &'b mut SectionSetter<'a>
where K: Into<String>, V: Into<String>, 'a: 'b,

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}
Source

pub fn add<'b, K, V>( &'b mut self, key: K, value: V, ) -> &'b mut SectionSetter<'a>
where K: Into<String>, V: Into<String>, 'a: 'b,

Add (append) key-value pair in this section

Source

pub fn delete<'b, K>(&'b mut self, key: &K) -> &'b mut SectionSetter<'a>
where K: AsRef<str>, 'a: 'b,

Delete the first entry in this section with key

Source

pub fn get<K: AsRef<str>>(&'a self, key: K) -> Option<&'a str>

Get the 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.