10 releases (4 stable)
new 1.1.2 | Jan 9, 2025 |
---|---|
1.1.1 | Dec 15, 2024 |
0.1.2 | May 3, 2020 |
0.1.1 | Mar 22, 2020 |
#102 in Configuration
645 downloads per month
Used in chewdata
20KB
79 lines
env_applier
env_applier is a Rust crate that applies environment variables to placeholders in a string, making configuration handling simple and flexible.
Getting Started
Installation
Add the following line to your Cargo.toml:
[dependencies]
env_applier = "x.y.z" # Replace with the latest version
Quick Start
Basic Example
extern crate env_applier;
use env_applier::*;
fn main() -> () {
let config = r#"{"test":"{{ HOME }}"}"#.to_string().apply();
println!("My new config : {:?}", config);
}
In this example, {{ HOME }} is replaced with the value of the HOME environment variable.
Example with Prefix
extern crate env_applier;
use env_applier::*;
fn main() -> () {
let config = r#"{"test":"{{ HOME }}"}"#.to_string().apply_with_prefix("MY_PREFIX");
println!("My new config : {:?}", config);
}
When using apply_with_prefix
, only environment variables prefixed with MY_PREFIX
will be considered.
Useful link
Contributing
Contributions are welcome!
To contribute:
- Fork the repository and create your branch (git checkout -b feature/my-feature).
- Commit your changes (git commit -m 'Add some feature').
- Push to the branch (git push origin feature/my-feature).
- Open a pull request.
For major changes, please open an issue first to discuss your proposal.
Please ensure that tests are added or updated as appropriate.
License
Licensed under either of the following, at your option: