Crates.io | simple_config_parser |
lib.rs | simple_config_parser |
version | 1.0.0 |
source | src |
created_at | 2021-07-07 19:48:03.788057 |
updated_at | 2021-11-05 03:32:44.550748 |
description | A simple configuration file parser |
homepage | |
repository | https://github.com/Basicprogrammer10/Rust-ConfigParser |
max_upload_size | |
id | 420008 |
size | 56,097 |
⚙ 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
Just add the following to your Cargo.toml
:
[dependencies]
simple_config_parser = "1.0.0"
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"
There are already a few config parsers out there for rust so why use this one?
There are a few reasons:
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);