| Crates.io | confetti-rs |
| lib.rs | confetti-rs |
| version | 0.1.1 |
| created_at | 2025-04-18 17:33:04.589795+00 |
| updated_at | 2025-04-18 19:03:15.003711+00 |
| description | A configuration language and parser library written in Rust |
| homepage | |
| repository | https://github.com/shkmv/confetti-rs |
| max_upload_size | |
| id | 1639708 |
| size | 149,876 |
A configuration language and parser library for Rust, with a flexible mapper for converting between configuration files and Rust structs.
Add this to your Cargo.toml:
[dependencies]
confetti-rs = { version = "0.1.1", features = ["derive"] }
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(())
}
For more examples and detailed documentation, please visit: