[−][src]Struct tini::Ini
Structure for INI-file data
Implementations
impl Ini
[src]
pub fn new() -> Ini
[src]
Create an empty Ini
pub fn from_file<S: AsRef<Path> + ?Sized>(path: &S) -> Result<Ini, Error>
[src]
Construct Ini from file
Errors
Errors returned by File::open()
and BufReader::read_to_string()
Examples
You may use Path
let path = Path::new("./examples/example.ini"); let conf = Ini::from_file(path); assert!(conf.ok().is_some());
or &str
let conf = Ini::from_file("./examples/example.ini"); assert!(conf.ok().is_some());
pub fn from_buffer<S: Into<String>>(buf: S) -> Ini
[src]
Construct Ini from buffer
Example
let conf = Ini::from_buffer("[section]\none = 1"); let value: Option<u8> = conf.get("section", "one"); assert_eq!(value, Some(1));
pub fn section<S: Into<String>>(self, name: S) -> Self
[src]
Set section name for following item()
s. This function doesn't create a
section.
Example
let conf = Ini::new().section("empty"); assert_eq!(conf.to_buffer(), String::new());
pub fn item<S: Into<String>>(self, name: S, value: S) -> Self
[src]
Add key-value pair to last section
Example
let conf = Ini::new().section("test") .item("value", "10"); let value: Option<u8> = conf.get("test", "value"); assert_eq!(value, Some(10));
pub fn to_file<S: AsRef<Path> + ?Sized>(&self, path: &S) -> Result<(), Error>
[src]
Write Ini to file. This function is similar to from_file
in use.
Errors
Errors returned by File::create()
and BufWriter::write_all()
pub fn to_buffer(&self) -> String
[src]
Write Ini to buffer
Example
let conf = Ini::from_buffer("[section]\none = 1"); // you may use `conf.to_buffer()` let value: String = conf.to_buffer(); // or format!("{}", conf); // let value: String = format!("{}", conf); // but the result will be the same assert_eq!(value, "[section]\none = 1");
pub fn get<T: FromStr>(&self, section: &str, key: &str) -> Option<T>
[src]
Get scalar value of key in section
Example
let conf = Ini::from_buffer("[section]\none = 1"); let value: Option<u8> = conf.get("section", "one"); assert_eq!(value, Some(1));
pub fn get_vec<T>(&self, section: &str, key: &str) -> Option<Vec<T>> where
T: FromStr,
[src]
T: FromStr,
Get vector value of key in section
The function returns None
if one of the elements can not be parsed.
Example
let conf = Ini::from_buffer("[section]\nlist = 1, 2, 3, 4"); let value: Option<Vec<u8>> = conf.get_vec("section", "list"); assert_eq!(value, Some(vec![1, 2, 3, 4]));
pub fn iter_section(&self, section: &str) -> Option<Iter<'_, String, String>>
[src]
Iterate over a section by a name
Example
let conf = Ini::from_buffer(["[search]", "g = google.com", "dd = duckduckgo.com"].join("\n")); let search = conf.iter_section("search").unwrap(); for (k, v) in search { println!("key: {} value: {}", k, v); }
pub fn iter(&self) -> IniIter<'_>
[src]
Iterate over all sections, yielding pairs of section name and iterator
over the section elements. The concrete iterator element type is
(&'a String, ordered_hashmap::Iter<'a, String, String>)
.
Example
let conf = Ini::new().section("foo") .item("item", "value") .item("other", "something") .section("bar") .item("one", "1"); for (section, iter) in conf.iter() { for (key, val) in iter { println!("section: {} key: {} val: {}", section, key, val); } }
pub fn iter_mut(&mut self) -> IniIterMut<'_>
[src]
Iterate over all sections, yielding pairs of section name and mutable
iterator over the section elements. The concrete iterator element type is
(&'a String, ordered_hashmap::IterMut<'a, String, String>)
.
Example
let mut conf = Ini::new().section("foo") .item("item", "value") .item("other", "something") .section("bar") .item("one", "1"); for (section, iter_mut) in conf.iter_mut() { for (key, val) in iter_mut { *val = String::from("replaced"); } }
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Ini
impl Send for Ini
impl Sync for Ini
impl Unpin for Ini
impl UnwindSafe for Ini
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,