Go to file
2025-07-15 14:33:51 +03:00
.github/workflows ci: fix docs 2025-07-14 22:02:16 +03:00
filecaster refactor(workspace): make a workspace 2025-07-15 14:33:51 +03:00
filecaster-derive refactor(workspace): make a workspace 2025-07-15 14:33:51 +03:00
.gitignore Initial commit 2025-07-14 18:14:49 +03:00
Cargo.lock refactor(workspace): make a workspace 2025-07-15 14:33:51 +03:00
Cargo.toml refactor(workspace): make a workspace 2025-07-15 14:33:51 +03:00
LICENSE-APACHE Create LICENSE-APACHE 2025-07-14 19:02:54 +03:00
LICENSE-MIT Create LICENSE-MIT 2025-07-14 19:03:11 +03:00
README.md test: add integration tests 2025-07-14 21:11:18 +03:00

derive(FromFile)

Procedural macro to derive configuration from files, with optional merging capabilities.

Features

  • Derive Configuration: Easily load configuration from files into your Rust structs.
  • Default Values: Specify default values for struct fields using the #[default = "..."] attribute.
  • Optional Merging: When the merge feature is enabled, allows merging multiple configuration sources.

Usage

[dependencies]
filecaster = "0.1"
use filecaster::FromFile;

#[derive(Debug, Clone, FromFile)]
pub struct MyConfig {
    #[from_file(default = "localhost")]
    pub host: String,
    #[from_file(default = 8080)]
    pub port: u16,
    #[from_file(default = false)]
    pub enabled: bool,
}

fn main() {
    // Simulate loading from a file (e.g., JSON, YAML, TOML)
    let file_content = r#"
        {
            "host": "localhost"
        }
    "#;

    let config_from_file: MyConfig = serde_json::from_str(file_content).unwrap();
    let config = MyConfig::from_file(Some(config_from_file));

    println!("Config: {:?}", config);
    // Expected output: Config { host: "localhost", port: 8080, enabled: false }
}

Documentation

Full documentation is available at docs.rs.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is dual-licensed under either:

at your option.