env_plus

Crates.ioenv_plus
lib.rsenv_plus
version0.1.2
sourcesrc
created_at2021-01-25 23:18:01.273233
updated_at2021-01-27 00:48:41.060628
descriptionA very simple crate used to load ENV variables in your program, but can also be customized to load your own files.
homepage
repositoryhttps://github.com/Jint3x/env_plus
max_upload_size
id346679
size12,267
Jint3x (Jint3x)

documentation

README

env_plus

Crates.io

A very simple and highly costumizeable env variable loader. You can specify your own files that you want to use or use its default settings.


Usage

Add this to your Cargo.toml:

[dependenices]
env_plus = "0.1.2"

.env_plus

// This is a comment!
SECRET=YOUR_SECRET

main.rs

use env_plus::EnvLoader;

fn main() {
    EnvLoader::new()
    .activate();

    let secret = std::env::var("SECRET").unwrap();
    assert_eq!(secret, String::from("YOUR_SECRET"));
}

The default settings for env_plus are:

  • File: .env_plus
  • Comments: //
  • Value delimiter: =
  • Overwrite existing variables with the same name: false

However, you are allowed to fully costumize which files to use and how to parse them.


Advanced Usage

special_file.extension

## I want to use this style as a comment!
## == will be the new value delimiter

SECRET==YOUR_SECRET

main.rs

use env_plus::EnvLoader;

fn main() {
    std::env::set_var("SECRET", "MY_SECRET");

    EnvLoader::new()
    .change_file(String::from("./special_file.extension"))
    .change_delimiter(String::from("=="))
    .change_comment(String::from("##"))
    .overwrite_envs(true)
    .activate();


    let secret = std::env::var("SECRET").unwrap();

    // SECRET has been overwritten from MY_SECRET to YOUR_SECRET
    assert_eq!(secret, String::from("YOUR_SECRET"));
}
Commit count: 5

cargo fmt