| Crates.io | inline-config |
| lib.rs | inline-config |
| version | 0.3.1 |
| created_at | 2025-12-30 20:25:18.99081+00 |
| updated_at | 2026-01-19 03:16:57.59402+00 |
| description | Effortlessly embed config modules and access with any compatible types |
| homepage | https://github.com/YishiMichael/inline-config |
| repository | https://github.com/YishiMichael/inline-config |
| max_upload_size | |
| id | 2013260 |
| size | 41,483 |
Effortlessly embed config modules and access with any compatible types.
A procedual macro config is provided to parse sources at compile time, generate corresponding data structures, from which we can access values via the Index trait and the From trait.
indexmap enables preserving orders of tables. Check this example for details.Add inline-config to your dependencies
cargo add inline-config
In your source file, declare a module using config holding the config data
use inline_config::config;
// Declare a config module containing literal sources.
// With `export(static = MY_CONFIG)`,
// a static variable `MY_CONFIG` will be brought into scope.
#[config(export(static = MY_CONFIG))]
mod my_config {
// When there are multiple sources,
// latter ones overwrite former ones.
toml!(
r#"
title = "TOML example"
[server]
owner = "Tom"
timeout = 2000
ports = [ 8000, 8001, 8002 ]
"#
);
toml!(
r#"
[server]
timeout = 5000
"#
);
// Including a file from disk is also possible,
// see `examples/include.rs`.
}
Then, access the data inside using the path!() macro
use inline_config::path;
// Use `Index`, `From` traits to access data.
// Different types may be accessible from a field.
let title: &str = MY_CONFIG[path!(title)].into();
assert_eq!("TOML example", title);
let title: String = MY_CONFIG[path!(title)].into();
assert_eq!("TOML example", title);
// A deeper path.
let owner: &str = MY_CONFIG[path!(server.owner)].into();
assert_eq!("Tom", owner);
// Any numerical types.
let timeout: u32 = MY_CONFIG[path!(server.timeout)].into();
assert_eq!(5000, timeout);
let timeout: f32 = MY_CONFIG[path!(server.timeout)].into();
// A homogeneous array can be accessed as `Vec<T>`.
let ports: Vec<u64> = MY_CONFIG[path!(server.ports)].into();
assert_eq!([8000, 8001, 8002].to_vec(), ports);
Check out more examples for more details about usage.