6 releases

0.2.1 Jan 22, 2023
0.2.0 Jan 21, 2023
0.1.3 Nov 20, 2021
0.1.2 Dec 22, 2020
0.1.1 Jun 21, 2020

#620 in Parser implementations

Download history 37/week @ 2023-02-09 42/week @ 2023-02-16 46/week @ 2023-02-23 66/week @ 2023-03-02 19/week @ 2023-03-09 22/week @ 2023-03-16 9/week @ 2023-03-23 8/week @ 2023-03-30 17/week @ 2023-04-06 42/week @ 2023-04-13 31/week @ 2023-04-20 12/week @ 2023-04-27 29/week @ 2023-05-04 20/week @ 2023-05-11 8/week @ 2023-05-18 32/week @ 2023-05-25

91 downloads per month
Used in procmon-oprs

MIT license

14KB
290 lines

Light INI parser

Rust

This library implements an event-driven parser for the INI file format.

It doesn't load data in a container. It's an alternative to rust-ini that avoids building an intermediate hash map if it's not necessary.

[dependencies]
light_ini = "0.2"

See the documentation and examples for details.

Format

  • There is no limitation in the names of the properties.

  • Comments are only allowed in their own line. The default character to start a comment is ;. Use IniParser::with_start_comment to use a different character such as #.

  • There is no escape or quoting characters

License

Licensed under MIT license.


lib.rs:

Light Ini file parser.

light-ini implements an event-driven parser for the INI file format. The handler must implement IniHandler.

use light_ini::{IniHandler, IniParser, IniHandlerError};

struct Handler {}

impl IniHandler for Handler {
    type Error = IniHandlerError;

    fn section(&mut self, name: &str) -> Result<(), Self::Error> {
        println!("section {}", name);
        Ok(())
    }

    fn option(&mut self, key: &str, value: &str) -> Result<(), Self::Error> {
        println!("option {} is {}", key, value);
        Ok(())
    }

    fn comment(&mut self, comment: &str) -> Result<(), Self::Error> {
        println!("comment: {}", comment);
        Ok(())
    }
}

let mut handler = Handler{};
let mut parser = IniParser::new(&mut handler);
parser.parse_file("example.ini");

Dependencies

~1MB
~17K SLoC