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?
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());
}
sourcepub fn with_section<S>(&mut self, section: Option<S>) -> SectionSetter<'_>where
S: Into<String>,
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?
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());
}
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?
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());
}
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>where
S: Into<String>,
pub fn section<S>(&self, name: Option<S>) -> Option<&Properties>where S: Into<String>,
Get a immutable section
Examples found in repository?
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());
}
sourcepub fn section_mut<S>(&mut self, name: Option<S>) -> Option<&mut Properties>where
S: Into<String>,
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?
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());
}
sourcepub fn section_all<S>(
&self,
name: Option<S>
) -> impl DoubleEndedIterator<Item = &Properties>where
S: Into<String>,
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
sourcepub fn section_all_mut<S>(
&mut self,
name: Option<S>
) -> impl DoubleEndedIterator<Item = &mut Properties>where
S: Into<String>,
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
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)where
S: Into<String>,
pub fn set_to<S>(&mut self, section: Option<S>, key: String, value: String)where S: Into<String>,
Set key-value to a section
sourcepub fn get_from<'a, S>(
&'a self,
section: Option<S>,
key: &str
) -> Option<&'a str>where
S: Into<String>,
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"));
sourcepub fn get_from_or<'a, S>(
&'a self,
section: Option<S>,
key: &str,
default: &'a str
) -> &'a strwhere
S: Into<String>,
pub fn get_from_or<'a, S>( &'a self, section: Option<S>, key: &str, default: &'a str ) -> &'a strwhere 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");
sourcepub fn get_from_mut<'a, S>(
&'a mut self,
section: Option<S>,
key: &str
) -> Option<&'a mut str>where
S: Into<String>,
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
sourcepub fn delete<S>(&mut self, section: Option<S>) -> Option<Properties>where
S: Into<String>,
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§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?
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());
}
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?
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());
}
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?
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());
}
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?
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());
}
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.