Crate cruct

Source
Expand description

cruct - Ease the creation of configuration files in Rust

A procedural macro for loading configuration files into Rust structs with compile-time validation and type safety.

§Example

use cruct::cruct;

#[cruct(load_config(path = "tests/fixtures/test_config.toml"))]
struct Config {
    #[field(default = 8080)]
    http_port: u16,
    database_url: String,
}

let cfg = Config::loader()
    .with_config()
    .load()
    .unwrap();

Modules§

parser
source

Structs§

CliSource
ConfigBuilder
Builder for creating a configuration from multiple sources.
ConfigFileSource

Enums§

ConfigValue
This enum represents the possible values that can be parsed from a configuration file.
FileFormat
Represents the supported file formats for configuration parsing.
ParserError
Represents various errors that can occur during the parsing process. Leverages the thiserror crate for structured and user-friendly error handling.

Traits§

ConfigSource
Trait defining a configuration source.
FromConfigValue
Trait to convert a ConfigValue to a specific type.
Parser
Trait defining the interface for parsers. Parsers must be thread-safe (Send + Sync).

Functions§

get_parser
Function to get a parser based on file extension. Returns an Option containing the parser if the extension is supported.

Attribute Macros§

cruct
Macro to load configuration files into Rust structs.