#ini

simple_config_parser

A simple configuration file parser

5 releases (1 stable)

1.0.0 Nov 5, 2021
0.1.6 Aug 3, 2021
0.1.5 Jul 8, 2021

#364 in Parser tooling

Download history 32/week @ 2024-06-16 25/week @ 2024-06-23 7/week @ 2024-06-30 10/week @ 2024-07-07 29/week @ 2024-07-14 28/week @ 2024-07-21 33/week @ 2024-07-28 25/week @ 2024-08-04 41/week @ 2024-08-11 23/week @ 2024-08-18 31/week @ 2024-08-25 45/week @ 2024-09-01 41/week @ 2024-09-08 34/week @ 2024-09-15 44/week @ 2024-09-22 185/week @ 2024-09-29

309 downloads per month

GPL-3.0 license

18KB
103 lines

Rust-ConfigParser CI Crates.io Lines of code

⚙ Very simple config parsing lib for rust!

I made this because I just needed a simple config parser for one of my projects and wanted to learn how to make a rust crate. Hopefully you will find it useful as well. :P

💠 Install

Just add the following to your Cargo.toml:

[dependencies]
simple_config_parser = "1.0.0"

📀 Quick Start

This config parser is made for use with a simplified version of an ini file. There are no sections and currently no Escape character support.

; This is a comment
# This is also a comment
hello = World
rust = Is great
test = "TEST"

🐳 Why

There are already a few config parsers out there for rust so why use this one?

There are a few reasons:

  • It's super simple to use
  • Its faster then some other popular config parsers (by only a few hundred Nano seconds but still)
  • It's code is easy to understand (For me at least)
  • It would make me happy (:P)

💥 Examples

Create a new config from text and a file.

// Import Lib
use simple_config_parser::Config;

// Create a new config and parse text
let cfg = Config::new()
    .text("hello = world")
    .unwrap();

// Create a new config from a file
let cfg2 = Config::new()
    .file("config.cfg")
    .unwrap();

Get a value from a config.

// Import Lib
use simple_config_parser::Config;

// Create a new config with no file
let cfg = Config::new()
    .text("hello = World\nrust = Is great")
    .unwrap();

// Get a value from the config (As a string)
println!("Hello, {}", cfg.get_str("hello").unwrap());

Get value from a config as any type that implements FromStr.

// Import Lib
use simple_config_parser::Config;

// Create a new config with no file
let mut cfg = Config::new()
    .text("hello = true\nrust = 15\npi = 3.1415926535")
    .unwrap();

// Get a value from the config as bool
assert_eq!(cfg.get::<bool>("hello").unwrap(), true);

// Get a value from the config as int
assert_eq!(cfg.get::<i32>("rust").unwrap(), 15);

// Get a value from the config as float
assert_eq!(cfg.get::<f32>("pi").unwrap(), 3.1415926535);

No runtime deps