#env #env-var #apply #applier

bin+lib env_applier

Apply environment variables on an object

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

Download history 22/week @ 2024-09-23 13/week @ 2024-11-04 343/week @ 2024-12-09 295/week @ 2024-12-16 119/week @ 2025-01-06

645 downloads per month
Used in chewdata

GPL-3.0 license

20KB
79 lines

env_applier

Actions Status semantic-release crates.io

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.



Contributing

Contributions are welcome!

To contribute:

  1. Fork the repository and create your branch (git checkout -b feature/my-feature).
  2. Commit your changes (git commit -m 'Add some feature').
  3. Push to the branch (git push origin feature/my-feature).
  4. 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:

No runtime deps