Struct ini::Ini

source ·
pub struct Ini { /* private fields */ }
Expand description

Ini struct

Implementations§

source§

impl Ini

source

pub fn new() -> Ini

Create an instance

Examples found in repository?
examples/test.rs (line 8)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
    let mut conf = Ini::new();
    conf.with_section(None::<String>).set("encoding", "utf-8");
    conf.with_section(Some("User"))
        .set("name", "Raspberry树莓")
        .set("value", "Pi");
    conf.with_section(Some("Library"))
        .set("name", "Sun Yat-sen U")
        .set("location", "Guangzhou=world\x0ahahaha");

    conf.section_mut(Some("Library")).unwrap().insert("seats", "42");

    println!("---------------------------------------");
    println!("Writing to file {:?}\n", CONF_FILE_NAME);
    conf.write_to(&mut stdout()).unwrap();

    conf.write_to_file(CONF_FILE_NAME).unwrap();

    println!("----------------------------------------");
    println!("Reading from file {:?}", CONF_FILE_NAME);
    let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();

    println!("Iterating");
    let general_section_name = "__General__";
    for (sec, prop) in i.iter() {
        let section_name = sec.as_ref().unwrap_or(&general_section_name);
        println!("-- Section: {:?} begins", section_name);
        for (k, v) in prop.iter() {
            println!("{}: {:?}", k, v);
        }
    }
    println!();

    let section = i.section(Some("User")).unwrap();
    println!("name={}", section.get("name").unwrap());
    println!("conf[User][name]={}", &i["User"]["name"]);
    println!("General Section: {:?}", i.general_section());
}
source

pub fn with_section<S>(&mut self, section: Option<S>) -> SectionSetter<'_>
where S: Into<String>,

Set with a specified section, None is for the general section

Examples found in repository?
examples/test.rs (line 9)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
    let mut conf = Ini::new();
    conf.with_section(None::<String>).set("encoding", "utf-8");
    conf.with_section(Some("User"))
        .set("name", "Raspberry树莓")
        .set("value", "Pi");
    conf.with_section(Some("Library"))
        .set("name", "Sun Yat-sen U")
        .set("location", "Guangzhou=world\x0ahahaha");

    conf.section_mut(Some("Library")).unwrap().insert("seats", "42");

    println!("---------------------------------------");
    println!("Writing to file {:?}\n", CONF_FILE_NAME);
    conf.write_to(&mut stdout()).unwrap();

    conf.write_to_file(CONF_FILE_NAME).unwrap();

    println!("----------------------------------------");
    println!("Reading from file {:?}", CONF_FILE_NAME);
    let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();

    println!("Iterating");
    let general_section_name = "__General__";
    for (sec, prop) in i.iter() {
        let section_name = sec.as_ref().unwrap_or(&general_section_name);
        println!("-- Section: {:?} begins", section_name);
        for (k, v) in prop.iter() {
            println!("{}: {:?}", k, v);
        }
    }
    println!();

    let section = i.section(Some("User")).unwrap();
    println!("name={}", section.get("name").unwrap());
    println!("conf[User][name]={}", &i["User"]["name"]);
    println!("General Section: {:?}", i.general_section());
}
source

pub fn with_general_section(&mut self) -> SectionSetter<'_>

Set with general section, a simple wrapper of with_section(None::<String>)

source

pub fn general_section(&self) -> &Properties

Get the immutable general section

Examples found in repository?
examples/test.rs (line 43)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
    let mut conf = Ini::new();
    conf.with_section(None::<String>).set("encoding", "utf-8");
    conf.with_section(Some("User"))
        .set("name", "Raspberry树莓")
        .set("value", "Pi");
    conf.with_section(Some("Library"))
        .set("name", "Sun Yat-sen U")
        .set("location", "Guangzhou=world\x0ahahaha");

    conf.section_mut(Some("Library")).unwrap().insert("seats", "42");

    println!("---------------------------------------");
    println!("Writing to file {:?}\n", CONF_FILE_NAME);
    conf.write_to(&mut stdout()).unwrap();

    conf.write_to_file(CONF_FILE_NAME).unwrap();

    println!("----------------------------------------");
    println!("Reading from file {:?}", CONF_FILE_NAME);
    let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();

    println!("Iterating");
    let general_section_name = "__General__";
    for (sec, prop) in i.iter() {
        let section_name = sec.as_ref().unwrap_or(&general_section_name);
        println!("-- Section: {:?} begins", section_name);
        for (k, v) in prop.iter() {
            println!("{}: {:?}", k, v);
        }
    }
    println!();

    let section = i.section(Some("User")).unwrap();
    println!("name={}", section.get("name").unwrap());
    println!("conf[User][name]={}", &i["User"]["name"]);
    println!("General Section: {:?}", i.general_section());
}
source

pub fn general_section_mut(&mut self) -> &mut Properties

Get the mutable general section

source

pub fn section<S>(&self, name: Option<S>) -> Option<&Properties>
where S: Into<String>,

Get a immutable section

Examples found in repository?
examples/test.rs (line 40)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
    let mut conf = Ini::new();
    conf.with_section(None::<String>).set("encoding", "utf-8");
    conf.with_section(Some("User"))
        .set("name", "Raspberry树莓")
        .set("value", "Pi");
    conf.with_section(Some("Library"))
        .set("name", "Sun Yat-sen U")
        .set("location", "Guangzhou=world\x0ahahaha");

    conf.section_mut(Some("Library")).unwrap().insert("seats", "42");

    println!("---------------------------------------");
    println!("Writing to file {:?}\n", CONF_FILE_NAME);
    conf.write_to(&mut stdout()).unwrap();

    conf.write_to_file(CONF_FILE_NAME).unwrap();

    println!("----------------------------------------");
    println!("Reading from file {:?}", CONF_FILE_NAME);
    let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();

    println!("Iterating");
    let general_section_name = "__General__";
    for (sec, prop) in i.iter() {
        let section_name = sec.as_ref().unwrap_or(&general_section_name);
        println!("-- Section: {:?} begins", section_name);
        for (k, v) in prop.iter() {
            println!("{}: {:?}", k, v);
        }
    }
    println!();

    let section = i.section(Some("User")).unwrap();
    println!("name={}", section.get("name").unwrap());
    println!("conf[User][name]={}", &i["User"]["name"]);
    println!("General Section: {:?}", i.general_section());
}
source

pub fn section_mut<S>(&mut self, name: Option<S>) -> Option<&mut Properties>
where S: Into<String>,

Get a mutable section

Examples found in repository?
examples/test.rs (line 17)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
    let mut conf = Ini::new();
    conf.with_section(None::<String>).set("encoding", "utf-8");
    conf.with_section(Some("User"))
        .set("name", "Raspberry树莓")
        .set("value", "Pi");
    conf.with_section(Some("Library"))
        .set("name", "Sun Yat-sen U")
        .set("location", "Guangzhou=world\x0ahahaha");

    conf.section_mut(Some("Library")).unwrap().insert("seats", "42");

    println!("---------------------------------------");
    println!("Writing to file {:?}\n", CONF_FILE_NAME);
    conf.write_to(&mut stdout()).unwrap();

    conf.write_to_file(CONF_FILE_NAME).unwrap();

    println!("----------------------------------------");
    println!("Reading from file {:?}", CONF_FILE_NAME);
    let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();

    println!("Iterating");
    let general_section_name = "__General__";
    for (sec, prop) in i.iter() {
        let section_name = sec.as_ref().unwrap_or(&general_section_name);
        println!("-- Section: {:?} begins", section_name);
        for (k, v) in prop.iter() {
            println!("{}: {:?}", k, v);
        }
    }
    println!();

    let section = i.section(Some("User")).unwrap();
    println!("name={}", section.get("name").unwrap());
    println!("conf[User][name]={}", &i["User"]["name"]);
    println!("General Section: {:?}", i.general_section());
}
source

pub fn section_all<S>( &self, name: Option<S>, ) -> impl DoubleEndedIterator<Item = &Properties>
where S: Into<String>,

Get all sections immutable with the same key

source

pub fn section_all_mut<S>( &mut self, name: Option<S>, ) -> impl DoubleEndedIterator<Item = &mut Properties>
where S: Into<String>,

Get all sections mutable with the same key

source

pub fn entry(&mut self, name: Option<String>) -> SectionEntry<'_>

Get the entry

source

pub fn clear(&mut self)

Clear all entries

source

pub fn sections(&self) -> impl DoubleEndedIterator<Item = Option<&str>>

Iterate with sections

source

pub fn set_to<S>(&mut self, section: Option<S>, key: String, value: String)
where S: Into<String>,

Set key-value to a section

source

pub fn get_from<'a, S>( &'a self, section: Option<S>, key: &str, ) -> Option<&'a str>
where S: Into<String>,

Get the first value from the sections with key

Example:

use ini::Ini;
let input = "[sec]\nabc = def\n";
let ini = Ini::load_from_str(input).unwrap();
assert_eq!(ini.get_from(Some("sec"), "abc"), Some("def"));
source

pub fn get_from_or<'a, S>( &'a self, section: Option<S>, key: &str, default: &'a str, ) -> &'a str
where S: Into<String>,

Get the first value from the sections with key, return the default value if it does not exist

Example:

use ini::Ini;
let input = "[sec]\n";
let ini = Ini::load_from_str(input).unwrap();
assert_eq!(ini.get_from_or(Some("sec"), "key", "default"), "default");
source

pub fn get_from_mut<'a, S>( &'a mut self, section: Option<S>, key: &str, ) -> Option<&'a mut str>
where S: Into<String>,

Get the first mutable value from the sections with key

source

pub fn delete<S>(&mut self, section: Option<S>) -> Option<Properties>
where S: Into<String>,

Delete the first section with key, return the properties if it exists

source

pub fn delete_from<S>( &mut self, section: Option<S>, key: &str, ) -> Option<String>
where S: Into<String>,

Delete the key from the section, return the value if key exists or None

source

pub fn len(&self) -> usize

Total sections count

source

pub fn is_empty(&self) -> bool

Check if object contains no section

source§

impl Ini

source

pub fn write_to_file<P: AsRef<Path>>(&self, filename: P) -> Result<()>

Write to a file

Examples found in repository?
examples/test.rs (line 23)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
    let mut conf = Ini::new();
    conf.with_section(None::<String>).set("encoding", "utf-8");
    conf.with_section(Some("User"))
        .set("name", "Raspberry树莓")
        .set("value", "Pi");
    conf.with_section(Some("Library"))
        .set("name", "Sun Yat-sen U")
        .set("location", "Guangzhou=world\x0ahahaha");

    conf.section_mut(Some("Library")).unwrap().insert("seats", "42");

    println!("---------------------------------------");
    println!("Writing to file {:?}\n", CONF_FILE_NAME);
    conf.write_to(&mut stdout()).unwrap();

    conf.write_to_file(CONF_FILE_NAME).unwrap();

    println!("----------------------------------------");
    println!("Reading from file {:?}", CONF_FILE_NAME);
    let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();

    println!("Iterating");
    let general_section_name = "__General__";
    for (sec, prop) in i.iter() {
        let section_name = sec.as_ref().unwrap_or(&general_section_name);
        println!("-- Section: {:?} begins", section_name);
        for (k, v) in prop.iter() {
            println!("{}: {:?}", k, v);
        }
    }
    println!();

    let section = i.section(Some("User")).unwrap();
    println!("name={}", section.get("name").unwrap());
    println!("conf[User][name]={}", &i["User"]["name"]);
    println!("General Section: {:?}", i.general_section());
}
source

pub fn write_to_file_policy<P: AsRef<Path>>( &self, filename: P, policy: EscapePolicy, ) -> Result<()>

Write to a file

source

pub fn write_to_file_opt<P: AsRef<Path>>( &self, filename: P, opt: WriteOption, ) -> Result<()>

Write to a file with options

source

pub fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>

Write to a writer

Examples found in repository?
examples/test.rs (line 21)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
    let mut conf = Ini::new();
    conf.with_section(None::<String>).set("encoding", "utf-8");
    conf.with_section(Some("User"))
        .set("name", "Raspberry树莓")
        .set("value", "Pi");
    conf.with_section(Some("Library"))
        .set("name", "Sun Yat-sen U")
        .set("location", "Guangzhou=world\x0ahahaha");

    conf.section_mut(Some("Library")).unwrap().insert("seats", "42");

    println!("---------------------------------------");
    println!("Writing to file {:?}\n", CONF_FILE_NAME);
    conf.write_to(&mut stdout()).unwrap();

    conf.write_to_file(CONF_FILE_NAME).unwrap();

    println!("----------------------------------------");
    println!("Reading from file {:?}", CONF_FILE_NAME);
    let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();

    println!("Iterating");
    let general_section_name = "__General__";
    for (sec, prop) in i.iter() {
        let section_name = sec.as_ref().unwrap_or(&general_section_name);
        println!("-- Section: {:?} begins", section_name);
        for (k, v) in prop.iter() {
            println!("{}: {:?}", k, v);
        }
    }
    println!();

    let section = i.section(Some("User")).unwrap();
    println!("name={}", section.get("name").unwrap());
    println!("conf[User][name]={}", &i["User"]["name"]);
    println!("General Section: {:?}", i.general_section());
}
source

pub fn write_to_policy<W: Write>( &self, writer: &mut W, policy: EscapePolicy, ) -> Result<()>

Write to a writer

source

pub fn write_to_opt<W: Write>( &self, writer: &mut W, opt: WriteOption, ) -> Result<()>

Write to a writer with options

source§

impl Ini

source

pub fn load_from_str(buf: &str) -> Result<Ini, ParseError>

Load from a string

source

pub fn load_from_str_noescape(buf: &str) -> Result<Ini, ParseError>

Load from a string, but do not interpret ’' as an escape character

source

pub fn load_from_str_opt(buf: &str, opt: ParseOption) -> Result<Ini, ParseError>

Load from a string with options

source

pub fn read_from<R: Read>(reader: &mut R) -> Result<Ini, Error>

Load from a reader

source

pub fn read_from_noescape<R: Read>(reader: &mut R) -> Result<Ini, Error>

Load from a reader, but do not interpret ’' as an escape character

source

pub fn read_from_opt<R: Read>( reader: &mut R, opt: ParseOption, ) -> Result<Ini, Error>

Load from a reader with options

source

pub fn load_from_file<P: AsRef<Path>>(filename: P) -> Result<Ini, Error>

Load from a file

Examples found in repository?
examples/test.rs (line 27)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
    let mut conf = Ini::new();
    conf.with_section(None::<String>).set("encoding", "utf-8");
    conf.with_section(Some("User"))
        .set("name", "Raspberry树莓")
        .set("value", "Pi");
    conf.with_section(Some("Library"))
        .set("name", "Sun Yat-sen U")
        .set("location", "Guangzhou=world\x0ahahaha");

    conf.section_mut(Some("Library")).unwrap().insert("seats", "42");

    println!("---------------------------------------");
    println!("Writing to file {:?}\n", CONF_FILE_NAME);
    conf.write_to(&mut stdout()).unwrap();

    conf.write_to_file(CONF_FILE_NAME).unwrap();

    println!("----------------------------------------");
    println!("Reading from file {:?}", CONF_FILE_NAME);
    let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();

    println!("Iterating");
    let general_section_name = "__General__";
    for (sec, prop) in i.iter() {
        let section_name = sec.as_ref().unwrap_or(&general_section_name);
        println!("-- Section: {:?} begins", section_name);
        for (k, v) in prop.iter() {
            println!("{}: {:?}", k, v);
        }
    }
    println!();

    let section = i.section(Some("User")).unwrap();
    println!("name={}", section.get("name").unwrap());
    println!("conf[User][name]={}", &i["User"]["name"]);
    println!("General Section: {:?}", i.general_section());
}
source

pub fn load_from_file_noescape<P: AsRef<Path>>( filename: P, ) -> Result<Ini, Error>

Load from a file, but do not interpret ’' as an escape character

source

pub fn load_from_file_opt<P: AsRef<Path>>( filename: P, opt: ParseOption, ) -> Result<Ini, Error>

Load from a file with options

source§

impl<'a> Ini

source

pub fn iter(&'a self) -> SectionIter<'a>

Immutable iterate though sections

Examples found in repository?
examples/test.rs (line 31)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
    let mut conf = Ini::new();
    conf.with_section(None::<String>).set("encoding", "utf-8");
    conf.with_section(Some("User"))
        .set("name", "Raspberry树莓")
        .set("value", "Pi");
    conf.with_section(Some("Library"))
        .set("name", "Sun Yat-sen U")
        .set("location", "Guangzhou=world\x0ahahaha");

    conf.section_mut(Some("Library")).unwrap().insert("seats", "42");

    println!("---------------------------------------");
    println!("Writing to file {:?}\n", CONF_FILE_NAME);
    conf.write_to(&mut stdout()).unwrap();

    conf.write_to_file(CONF_FILE_NAME).unwrap();

    println!("----------------------------------------");
    println!("Reading from file {:?}", CONF_FILE_NAME);
    let i = Ini::load_from_file(CONF_FILE_NAME).unwrap();

    println!("Iterating");
    let general_section_name = "__General__";
    for (sec, prop) in i.iter() {
        let section_name = sec.as_ref().unwrap_or(&general_section_name);
        println!("-- Section: {:?} begins", section_name);
        for (k, v) in prop.iter() {
            println!("{}: {:?}", k, v);
        }
    }
    println!();

    let section = i.section(Some("User")).unwrap();
    println!("name={}", section.get("name").unwrap());
    println!("conf[User][name]={}", &i["User"]["name"]);
    println!("General Section: {:?}", i.general_section());
}
source

pub fn mut_iter(&'a mut self) -> SectionIterMut<'a>

👎Deprecated: Use iter_mut instead!

Mutable iterate though sections

source

pub fn iter_mut(&'a mut self) -> SectionIterMut<'a>

Mutable iterate though sections

Trait Implementations§

source§

impl Clone for Ini

source§

fn clone(&self) -> Ini

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Ini

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Ini

source§

fn default() -> Self

Creates an ini instance with an empty general section. This allows Ini::general_section and Ini::with_general_section to be called without panicking.

source§

impl<'q> Index<&'q str> for Ini

§

type Output = Properties

The returned type after indexing.
source§

fn index<'a>(&'a self, index: &'q str) -> &'a Properties

Performs the indexing (container[index]) operation. Read more
source§

impl<S: Into<String>> Index<Option<S>> for Ini

§

type Output = Properties

The returned type after indexing.
source§

fn index(&self, index: Option<S>) -> &Properties

Performs the indexing (container[index]) operation. Read more
source§

impl<'q> IndexMut<&'q str> for Ini

source§

fn index_mut<'a>(&'a mut self, index: &'q str) -> &'a mut Properties

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<S: Into<String>> IndexMut<Option<S>> for Ini

source§

fn index_mut(&mut self, index: Option<S>) -> &mut Properties

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<'a> IntoIterator for &'a Ini

§

type IntoIter = SectionIter<'a>

Which kind of iterator are we turning this into?
§

type Item = (Option<&'a str>, &'a Properties)

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> IntoIterator for &'a mut Ini

§

type IntoIter = SectionIterMut<'a>

Which kind of iterator are we turning this into?
§

type Item = (Option<&'a str>, &'a mut Properties)

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl IntoIterator for Ini

§

type IntoIter = SectionIntoIter

Which kind of iterator are we turning this into?
§

type Item = (Option<String>, Properties)

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl Freeze for Ini

§

impl RefUnwindSafe for Ini

§

impl Send for Ini

§

impl Sync for Ini

§

impl Unpin for Ini

§

impl UnwindSafe for Ini

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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.