profig-macros

Crates.ioprofig-macros
lib.rsprofig-macros
version0.1.0
created_at2025-08-03 16:30:43.482034+00
updated_at2025-08-03 16:30:43.482034+00
descriptionHelper crate for Profig, providing the procedural macros of Profig.
homepage
repositoryhttps://github.com/aether-flux/profig
max_upload_size
id1779872
size20,709
Amartya Chowdhury (aether-flux)

documentation

README

Profig

A Config Framework with schema validation, sample configs, and doc generation

Load your config files, validate them, document them, all with #[derive(Profig)].


Features

  • Easy config schema definition with #[derive(Profig)]
  • Set strict formats with #[profig(formats="json,toml")]
  • Field-level metadata using #[profig(doc = "...", default = "...")]
  • Built-in validation with #[profig(min = 1, max = 10, regex = "...")]
  • Multi format support: TOML, JSON, YAML
  • Automatically load data by automatically determining file type (ie .json/.toml/.yaml)
  • Automatic sample generation with one sample_config("filename.format") (eg, sample_config("sample.json"))
  • Docs generation using the provided doc="..." metadata fields

Example Usage

use profig::Profig;

// Config Schema struct
#[derive(Profig)]
#[profig(formats="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);
}

Formats Supported

Currently, profig supports the following config file types:

  • JSON
  • TOML
  • YAML

Each 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

Full Documentation

See DOCS.md for complete documentation and guide on usage of profig.

Installation

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"] }

Status

Profig is currently in v0.1, stable for usage but still in very early stages.

Links

License

MIT

Commit count: 0

cargo fmt