Struct Ini

Source
pub struct Ini { /* private fields */ }
Expand description

Ini struct

Implementations§

Source§

impl Ini

Source

pub fn new() -> Ini

Create an instance

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

Source

pub fn general_section(&self) -> &HashMap<String, String>

Get the immmutable general section

Source

pub fn general_section_mut(&mut self) -> &mut HashMap<String, String>

Get the mutable general section

Source

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

Get a immutable section

Source

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

Get a mutable section

Source

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

Get the entry

Source

pub fn clear(&mut self)

Clear all entries

Source

pub fn sections(&self) -> Keys<'_, Option<String>, HashMap<String, String>>

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 value from a section 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 value from a section 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 str>
where S: Into<String>,

Get the mutable from a section with key

Source

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

Delete a section, 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>,

Source§

impl Ini

Source

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

Write to a file

Source

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

Write to a file

Source

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

Write to a writer

Source

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

Write to a writer

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>(reader: &mut R) -> Result<Ini, Error>
where R: Read,

Load from a reader

Source

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

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

Source

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

Load from a reader with options

Source

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

Load from a file

Source

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

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

Source

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

Load from a file with options

Source§

impl<'a> Ini

Source

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

Immutable iterate though sections

Source

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

Mutable iterate though sections Deprecated! Use iter_mut instead!

Source

pub fn iter_mut(&'a mut self) -> SectionMutIterator<'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 Default for Ini

Source§

fn default() -> Ini

Returns the “default value” for a type. Read more
Source§

impl<'q> Index<&'q Option<String>> for Ini

Source§

type Output = HashMap<String, String>

The returned type after indexing.
Source§

fn index<'a>(&'a self, index: &'q Option<String>) -> &'a HashMap<String, String>

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

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

Source§

type Output = HashMap<String, String>

The returned type after indexing.
Source§

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

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

impl<'i> IndexMut<&'i Option<String>> for Ini

Source§

fn index_mut<'a>( &'a mut self, index: &Option<String>, ) -> &'a mut HashMap<String, String>

Performs the mutable 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 HashMap<String, String>

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

impl<'a> IntoIterator for &'a Ini

Source§

type Item = (&'a Option<String>, &'a HashMap<String, String>)

The type of the elements being iterated over.
Source§

type IntoIter = SectionIterator<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> SectionIterator<'a>

Creates an iterator from a value. Read more
Source§

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

Source§

type Item = (&'a Option<String>, &'a mut HashMap<String, String>)

The type of the elements being iterated over.
Source§

type IntoIter = SectionMutIterator<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> SectionMutIterator<'a>

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Ini

Source§

type Item = (Option<String>, HashMap<String, String>)

The type of the elements being iterated over.
Source§

type IntoIter = SectionIntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> SectionIntoIter

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

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.