pretty_ini

Crates.iopretty_ini
lib.rspretty_ini
version0.1.7
sourcesrc
created_at2022-12-20 09:54:40.218412
updated_at2023-04-16 13:41:33.445357
descriptionLight library to read/write ini files
homepage
repositoryhttps://github.com/eVisualUser/pretty-ini
max_upload_size
id742165
size19,952
Sylvain (eVisualUser)

documentation

README

Pretty INI

Light library to read/write ini files.

Format

[table_name]
key = value

Example

use pretty_ini::{ini, ini_file};

fn main() {
    let mut file = ini_file::IniFile::default();
    file.set_path("demo.ini");

    let mut ini = ini::Ini::default();
    ini.load(&mut file).unwrap();

    let var_iter = ini.get_ref_mut(ini::TABLE_NAME_ROOT, "iter").unwrap();
    var_iter.set(var_iter.parse::<i32>().unwrap() + 1);

    println!("All keys contained in: \"Next\"");
    for key in ini
        .get_all_keys_in_table("next")
        .expect("No key found in Next")
    {
        println!("- {}", key);
    }

    file.save(&mut ini);
}


Pre/Post Process

In the IniFile you can add some process using a ProcessAction.

Pre Process

Called before assigning the file content to the buffer.

let action = Some(Box::new(|buffer| {
    // Do nothing
    return buffer;
}));

ini_file.add_pre_process(action);

Post Process

Called before saving the file.

let action = Some(Box::new(|buffer| {
    // Do nothing
    return buffer;
}));

ini_file.add_post_process(action);

⚠️ Warnings

  • The output when saving will be reformated.
  • Implicit "root" table.
Commit count: 30

cargo fmt