| Crates.io | easy-config-store |
| lib.rs | easy-config-store |
| version | 0.1.0 |
| created_at | 2025-03-14 12:59:11.159399+00 |
| updated_at | 2025-03-14 12:59:11.159399+00 |
| description | A simple, flexible configuration management library for Rust that supports multiple serialization formats and both synchronous and asynchronous operations. |
| homepage | https://github.com/GustavoWidman/easy-config-store |
| repository | https://github.com/GustavoWidman/easy-config-store |
| max_upload_size | |
| id | 1592174 |
| size | 28,186 |
A simple, flexible configuration management library for Rust that supports multiple serialization formats and both synchronous and asynchronous operations.
Add to your Cargo.toml:
[dependencies]
easy-config-store = { version = "0.1.0", features = ["json"] }
Choose features based on your needs:
json - JSON serialization supporttoml - TOML serialization support (preferred if multiple formats are enabled)yaml - YAML serialization supporttokio - Async support via Tokiouse easy_config_store::ConfigStore;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, PartialEq, Serialize, Deserialize, Clone)]
struct Config {
database_url: String,
password: String,
port: u16,
}
fn main() -> anyhow::Result<()> {
// Read or create config file
let mut config = ConfigStore::<Config>::read("config.json")?;
// Access config values directly (via Deref)
println!("Database URL: {}", config.database_url);
// Modify values
config.database_url = "postgres://localhost/mydb".into();
// Save changes
config.save()?;
Ok(())
}
use easy_config_store::ConfigStore;
use serde::{Deserialize, Serialize};
#[derive(Debug, Default, PartialEq, Serialize, Deserialize, Clone)]
struct Config {
database_url: String,
password: String,
port: u16,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut config = ConfigStore::<Config>::async_read("config.toml").await?;
config.password = "new_password".into();
config.async_save().await?;
Ok(())
}
ConfigStore<T>// Create or read config from a file (sync)
ConfigStore::<T>::read("path/to/config.json") -> Result<ConfigStore<T>, anyhow::Error>
// Create or read config from a file (async)
ConfigStore::<T>::async_read("path/to/config.json").await -> Result<ConfigStore<T>, anyhow::Error>
// Save config to file (sync)
config.save() -> Result<(), anyhow::Error>
// Save config to file (async)
config.async_save().await -> Result<(), anyhow::Error>
// Update from file (sync)
config.update() -> anyhow::Result<bool>
// Update from file (async)
config.async_update().await -> anyhow::Result<bool>
// Consume the ConfigStore and return the inner config
config.into_inner() -> T
The library includes several examples demonstrating various configurations:
To run an example:
cargo run --package json-std
When multiple serialization format features are enabled, the library prioritizes them in this order:
This project is licensed under the MIT License.