Rust-Decouple
Rust decouple is a long term project that aims to mimic the functionality of the python-decouple library
Due to the nature of the Rust language, the library will be implemented in a different way, but the goal is to provide a similar functionality. So far, the library is in a very early stage of development and is not ready for use.
The benefits of the rust version is that the cast is automatically done by the library, so you don't have to worry about it.
Usage
Basic usage
The most basic usage of the library is to get a variable from the environment, if it is not found, it will return an error.
use config;
...
let my_string: String = config!;
You can also specify a default value if the variable is not found
use config;
...
let my_string = config!;
In this case, the variable type will be inferred from the default value. If the default value is ambiguous, you can specify the type like this:
use config;
...
// The type is annotated by the user
let my_string: u8 = config!;
// The type is inferred from the default value
let my_string = config!;
Notice that this usage of default doesn't cover the case where the variable is found but is empty or invalid.
Vectorized environment variables
You can also get a vector of values from the environment, the values should be separated by a comma without spaces in between.
use config_vec;
...
let my_vec: = config_vec!;
let my_vec = config_vec!;
let my_vec: = config_vec!;