Crates.io | realme |
lib.rs | realme |
version | |
source | src |
created_at | 2024-09-16 12:09:35.680967 |
updated_at | 2024-12-25 02:39:34.759701 |
description | A flexible and extensible configuration management library for Rust, designed to simplify the process of loading and managing configuration settings from various sources. |
homepage | https://github.com/vainjoker/realme |
repository | https://github.com/vainjoker/realme |
max_upload_size | |
id | 1376270 |
Cargo.toml error: | TOML parse error at line 23, column 1 | 23 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Realme is a flexible and extensible configuration management library for Rust. It simplifies the process of loading and managing configuration settings from various sources. The name "Realme" is a play on "Realm" and "me," emphasizing its role in managing your application's configuration realm.
Add this to your Cargo.toml
:
[dependencies]
realme = {version = "0.1.4", features = ["toml"]}
You can also enable other features, for example, to use hot reloading feature, you need to enable json
andwatch
feature:
realme = {version = "0.1.4", features = ["toml", "json", "watch"]}
Here's a simple example of how to use Realme:
use realme::{Adaptor, Realme, StringSource, TomlParser};
use serde::{Serialize, Deserialize};
#[derive(Debug, Serialize, Deserialize)]
struct Person {
name: String,
age: u32,
birthday: chrono::DateTime<chrono::Utc>,
}
const CONFIGURATION1: &str = r#"
name = "John"
age = 30
birthday = 1993-01-01T00:00:00Z
"#;
fn main() {
let realme = Realme::builder()
.load(Adaptor::new(StringSource::<TomlParser>::new(
CONFIGURATION1,
)))
.build()
.expect("Building configuration object");
let person: Person = realme.try_deserialize().unwrap();
println!("{:?}", person);
println!("{:?}", realme);
assert_eq!(person.name, TryInto::<String>::try_into(realme.get("name").unwrap()).unwrap());
assert_eq!(person.age, realme.get_as::<u32, _>("age").unwrap());
assert_eq!(person.birthday, realme.get_as::<chrono::DateTime<chrono::Utc>, _>("birthday").unwrap());
}
For more detailed examples, check the examples
directory.
For a real-world example, you can check the Rinkle project.
I am impressed by the following libraries:
And compared to them, Realme has the following features:
serde
, so you can convert to any type that implements serde::Serialize
and serde::Deserialize
traitParser
and Source
traitBut Realme has the following drawbacks:
Contributions are welcome! Please feel free to submit a Pull Request.