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§
Structs§
- CliSource
- Config
Builder - Builder for creating a configuration from multiple sources.
- Config
File Source
Enums§
- Config
Value - This enum represents the possible values that can be parsed from a configuration file.
- File
Format - Represents the supported file formats for configuration parsing.
- Parser
Error - Represents various errors that can occur during the parsing process.
Leverages the
thiserror
crate for structured and user-friendly error handling.
Traits§
- Config
Source - Trait defining a configuration source.
- From
Config Value - 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.