| Crates.io | profig |
| lib.rs | profig |
| version | 0.1.1 |
| created_at | 2025-08-03 16:31:10.535584+00 |
| updated_at | 2025-08-05 15:12:25.047685+00 |
| description | Declarative config loader for Rust with schema validation, samples, and documentation generation. |
| homepage | |
| repository | https://github.com/aether-flux/profig |
| max_upload_size | |
| id | 1779874 |
| size | 28,033 |
A Config Framework with schema validation, sample configs, and doc generation
Load your config files, validate them, document them, all with
#[derive(Profig)].
#[derive(Profig)]#[profig(format="json,toml")]#[profig(doc = "...", default = "...")]#[profig(min = 1, max = 10, regex = "...")].json/.toml/.yaml)sample_config("filename.format") (eg, sample_config("sample.json"))doc="..." metadata fieldsuse profig::Profig;
// Config Schema struct
#[derive(Profig)]
#[profig(format="toml, json")]
struct AppConfig {
#[profig(min="4", max="10", doc="Number of worker threads")]
threads: usize,
#[profig(doc="Path to output directory")]
output_dir: String,
#[profig(default="false", doc="Enable debug mode")]
debug: Option<bool>,
}
// Main function
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load a JSON file
let jsonConf = AppStruct::load("config.json")?;
// Load a TOML file
let tomlConf = AppStruct::load("config.toml")?;
// Print fields from JSON-loaded object
println!("Threads: {}", jsonConf.threads);
// Print fields from TOML-loaded object
println!("Output directory: {}", tomlConf.output_dir);
}
Currently, profig supports the following config file types:
JSONTOMLYAMLEach format is gated behind their individual feature flags. Enable the features in Cargo.toml as follows:
[dependencies.profig]
version = "0.1"
features = ["toml", "json", "yaml"] # choose the features as per your requirements
See DOCS.md for complete documentation and guide on usage of profig.
Run the following command to install the crate:
cargo add profig
Or, for format features:
cargo add profig --features "toml,json"
Alternatively, you can directly add a Cargo.toml entry as follows:
[dependencies]
profig = { version = "0.1", features = ["toml", "yaml"] }
Profig is currently in v0.1, stable for usage but still in very early stages.
MIT