2 releases
new 0.1.1 | Apr 18, 2025 |
---|---|
0.1.0 | Apr 18, 2025 |
#1180 in Parser implementations
49 downloads per month
88KB
1.5K
SLoC
Confetti-rs
A configuration language and parser library for Rust, with a flexible mapper for converting between configuration files and Rust structs.
Features
- Simple, intuitive configuration syntax
- A powerful parser with customizable options
- Automatic mapping between configuration and Rust structs
- Support for custom data types
- Comprehensive error handling
Installation
Add this to your Cargo.toml
:
[dependencies]
confetti-rs = { version = "0.1.1", features = ["derive"] }
Basic Usage
use confetti_rs::{ConfMap, from_str, to_string};
use std::error::Error;
// Define a configuration structure
#[derive(ConfMap, Debug)]
struct ServerConfig {
host: String,
port: i32,
#[conf_map(name = "ssl-enabled")]
ssl_enabled: bool,
max_connections: Option<i32>,
}
fn main() -> Result<(), Box<dyn Error>> {
// Configuration string in Confetti syntax
let config_str = r#"
ServerConfig {
host "localhost";
port 8080;
ssl-enabled false;
max_connections 100;
}
"#;
// Parse the configuration
let server_config = from_str::<ServerConfig>(config_str)?;
println!("Loaded config: {:?}", server_config);
// Serialize to a string
let serialized = to_string(&server_config)?;
Ok(())
}
More Information
For more examples and detailed documentation, please visit:
Dependencies
~235KB