| Crates.io | ini_file_parser |
| lib.rs | ini_file_parser |
| version | 0.2.0 |
| created_at | 2024-11-13 14:44:39.55652+00 |
| updated_at | 2024-11-16 17:25:04.401188+00 |
| description | A Rust-based parser for INI configuration files, providing structured access to sections and key-value pairs. This parser helps read and manipulate configuration data commonly used in various applications. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1446595 |
| size | 27,648 |
This project is a Rust-based parser for INI configuration files. INI files are a simple, human-readable format for storing configuration data, where data is organized into sections, each containing key-value pairs.
The parser reads an INI file and parses its contents into a structured format. The output is a Config structure, which contains a collection of Section structs, each holding key-value pairs. This parser is useful for reading and manipulating configuration files commonly used in applications, games, and system settings.
The parsing process follows these steps:
[section_name]).=), with the key on the left and the value on the right.;), are ignored during parsing.The result of the parsing is stored in a Config structure, which contains multiple Section structs. Each Section contains a collection of KeyValue pairs.
To use the INI parser, simply provide the content of the INI file as a string to the parse_ini function. The function will return a Config object, which can be further used to access the parsed sections and key-value pairs.
WHITESPACE = _{ " " | "\t" }
file = { SOI ~ (NEWLINE* ~ (comment | section) ~ NEWLINE*)* ~ EOI }
section = {"[" ~ name ~ "]" ~ NEWLINE+ ~ (NEWLINE* ~ (comment | pair))* ~ NEWLINE+}
name = @{ UPPERCASE_LETTER+ }
pair = { key ~ "=" ~ (array_value | value) }
key = @{ (ALPHABETIC)+ }
value = @{ (!("," | WHITESPACE | NEWLINE | "[" | "]") ~ ANY)+ }
array_value = { "[" ~ WHITESPACE* ~ value ~ (WHITESPACE* ~ "," ~ WHITESPACE* ~ value)* ~ WHITESPACE* ~ "]" }
comment = { ";" ~ (!NEWLINE ~ ANY)* }
let ini_content = r#"
; This is a comment
[section1]
key1=value1
key2=value2
[section2]
keyA=valueA
"#;
let config = parse_ini(ini_content)?;
let first = config.get_value("key1") // result is Some("value1")
let second = config.get_value("aaaaaa") // result is None
let third = config.get_value_in_section("section1", "key2") // result is Some("value2")
Documentation: https://docs.rs/ini_file_parser/latest/ini_file_parser/index.html