More Options

More Options is a library for defining configuration options in Rust. Options can be initialized in code, bound from configuration, and/or composed through dependency injection (DI).
You may be looking for:
Features
This crate provides the following features:
- default - Abstractions for options
- async - Enable options in asynchronous contexts
- di - Dependency injection extensions
- cfg - Dependency injection extensions to bind configurations to options
Options Pattern
The options pattern uses structures to provide strongly typed access to groups of related settings without having to know how the settings were configured. The settings can be set explicitly in code or they can come from an external configuration source such as a file.
Consider the following options:
These might be used by a HTTP client as follows:
use Options;
use Rc;
Options in Action
The defined options can be used in any number of ways, including just explicitly specifying the settings.
use crate::*;
use Rc;
If you expect to process your options from an external data source, then you'll almost certainly require supporting deserialization using serde as follows:
use Deserialize;
Suppose you had the following appSettings.json file:
You can construct the options from the settings by including the more-config crate as follows:
use crate::*;
use ;
You can go one step further and combine that configuration with the more-di crate to assemble all of the pieces for you:
use crate::*;
use ;
use *;
use Rc;
License
This project is licensed under the MIT license.