pub struct Ini { /* private fields */ }
Expand description
Ini struct
Implementations§
Source§impl Ini
impl Ini
Sourcepub fn new() -> Ini
pub fn new() -> Ini
Create an instance
Examples found in repository?
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 with_section<S>(&mut self, section: Option<S>) -> SectionSetter<'_>
pub fn with_section<S>(&mut self, section: Option<S>) -> SectionSetter<'_>
Set with a specified section, None
is for the general section
Examples found in repository?
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 with_general_section(&mut self) -> SectionSetter<'_>
pub fn with_general_section(&mut self) -> SectionSetter<'_>
Set with general section, a simple wrapper of with_section(None::<String>)
Sourcepub fn general_section(&self) -> &Properties
pub fn general_section(&self) -> &Properties
Get the immutable general section
Examples found in repository?
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 general_section_mut(&mut self) -> &mut Properties
pub fn general_section_mut(&mut self) -> &mut Properties
Get the mutable general section
Sourcepub fn section<S>(&self, name: Option<S>) -> Option<&Properties>
pub fn section<S>(&self, name: Option<S>) -> Option<&Properties>
Get a immutable section
Examples found in repository?
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 section_mut<S>(&mut self, name: Option<S>) -> Option<&mut Properties>
pub fn section_mut<S>(&mut self, name: Option<S>) -> Option<&mut Properties>
Get a mutable section
Examples found in repository?
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 section_all<S>(
&self,
name: Option<S>,
) -> impl DoubleEndedIterator<Item = &Properties>
pub fn section_all<S>( &self, name: Option<S>, ) -> impl DoubleEndedIterator<Item = &Properties>
Get all sections immutable with the same key
Sourcepub fn section_all_mut<S>(
&mut self,
name: Option<S>,
) -> impl DoubleEndedIterator<Item = &mut Properties>
pub fn section_all_mut<S>( &mut self, name: Option<S>, ) -> impl DoubleEndedIterator<Item = &mut Properties>
Get all sections mutable with the same key
Sourcepub fn entry(&mut self, name: Option<String>) -> SectionEntry<'_>
pub fn entry(&mut self, name: Option<String>) -> SectionEntry<'_>
Get the entry
Sourcepub fn sections(&self) -> impl DoubleEndedIterator<Item = Option<&str>>
pub fn sections(&self) -> impl DoubleEndedIterator<Item = Option<&str>>
Iterate with sections
Sourcepub fn set_to<S>(&mut self, section: Option<S>, key: String, value: String)
pub fn set_to<S>(&mut self, section: Option<S>, key: String, value: String)
Set key-value to a section
Sourcepub fn get_from<'a, S>(
&'a self,
section: Option<S>,
key: &str,
) -> Option<&'a str>
pub fn get_from<'a, S>( &'a self, section: Option<S>, key: &str, ) -> Option<&'a str>
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"));
Sourcepub fn get_from_or<'a, S>(
&'a self,
section: Option<S>,
key: &str,
default: &'a str,
) -> &'a str
pub fn get_from_or<'a, S>( &'a self, section: Option<S>, key: &str, default: &'a str, ) -> &'a str
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");
Sourcepub fn get_from_mut<'a, S>(
&'a mut self,
section: Option<S>,
key: &str,
) -> Option<&'a mut str>
pub fn get_from_mut<'a, S>( &'a mut self, section: Option<S>, key: &str, ) -> Option<&'a mut str>
Get the first mutable value from the sections with key
Sourcepub fn delete<S>(&mut self, section: Option<S>) -> Option<Properties>
pub fn delete<S>(&mut self, section: Option<S>) -> Option<Properties>
Delete the first section with key, return the properties if it exists
Source§impl Ini
impl Ini
Sourcepub fn write_to_file<P: AsRef<Path>>(&self, filename: P) -> Result<()>
pub fn write_to_file<P: AsRef<Path>>(&self, filename: P) -> Result<()>
Write to a file
Examples found in repository?
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 write_to_file_policy<P: AsRef<Path>>(
&self,
filename: P,
policy: EscapePolicy,
) -> Result<()>
pub fn write_to_file_policy<P: AsRef<Path>>( &self, filename: P, policy: EscapePolicy, ) -> Result<()>
Write to a file
Sourcepub fn write_to_file_opt<P: AsRef<Path>>(
&self,
filename: P,
opt: WriteOption,
) -> Result<()>
pub fn write_to_file_opt<P: AsRef<Path>>( &self, filename: P, opt: WriteOption, ) -> Result<()>
Write to a file with options
Sourcepub fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>
pub fn write_to<W: Write>(&self, writer: &mut W) -> Result<()>
Write to a writer
Examples found in repository?
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 write_to_policy<W: Write>(
&self,
writer: &mut W,
policy: EscapePolicy,
) -> Result<()>
pub fn write_to_policy<W: Write>( &self, writer: &mut W, policy: EscapePolicy, ) -> Result<()>
Write to a writer
Sourcepub fn write_to_opt<W: Write>(
&self,
writer: &mut W,
opt: WriteOption,
) -> Result<()>
pub fn write_to_opt<W: Write>( &self, writer: &mut W, opt: WriteOption, ) -> Result<()>
Write to a writer with options
Source§impl Ini
impl Ini
Sourcepub fn load_from_str(buf: &str) -> Result<Ini, ParseError>
pub fn load_from_str(buf: &str) -> Result<Ini, ParseError>
Load from a string
Sourcepub fn load_from_str_noescape(buf: &str) -> Result<Ini, ParseError>
pub fn load_from_str_noescape(buf: &str) -> Result<Ini, ParseError>
Load from a string, but do not interpret ’' as an escape character
Sourcepub fn load_from_str_opt(buf: &str, opt: ParseOption) -> Result<Ini, ParseError>
pub fn load_from_str_opt(buf: &str, opt: ParseOption) -> Result<Ini, ParseError>
Load from a string with options
Sourcepub fn read_from_noescape<R: Read>(reader: &mut R) -> Result<Ini, Error>
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
Sourcepub fn read_from_opt<R: Read>(
reader: &mut R,
opt: ParseOption,
) -> Result<Ini, Error>
pub fn read_from_opt<R: Read>( reader: &mut R, opt: ParseOption, ) -> Result<Ini, Error>
Load from a reader with options
Sourcepub fn load_from_file<P: AsRef<Path>>(filename: P) -> Result<Ini, Error>
pub fn load_from_file<P: AsRef<Path>>(filename: P) -> Result<Ini, Error>
Load from a file
Examples found in repository?
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 load_from_file_noescape<P: AsRef<Path>>(
filename: P,
) -> Result<Ini, Error>
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
Sourcepub fn load_from_file_opt<P: AsRef<Path>>(
filename: P,
opt: ParseOption,
) -> Result<Ini, Error>
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
impl<'a> Ini
Sourcepub fn iter(&'a self) -> SectionIter<'a> ⓘ
pub fn iter(&'a self) -> SectionIter<'a> ⓘ
Immutable iterate though sections
Examples found in repository?
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 mut_iter(&'a mut self) -> SectionIterMut<'a> ⓘ
👎Deprecated: Use iter_mut
instead!
pub fn mut_iter(&'a mut self) -> SectionIterMut<'a> ⓘ
iter_mut
instead!Mutable iterate though sections
Sourcepub fn iter_mut(&'a mut self) -> SectionIterMut<'a> ⓘ
pub fn iter_mut(&'a mut self) -> SectionIterMut<'a> ⓘ
Mutable iterate though sections
Trait Implementations§
Source§impl Default for Ini
impl Default for Ini
Source§fn default() -> Self
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.