Crates.io | env_plus |
lib.rs | env_plus |
version | 0.1.2 |
source | src |
created_at | 2021-01-25 23:18:01.273233 |
updated_at | 2021-01-27 00:48:41.060628 |
description | A very simple crate used to load ENV variables in your program, but can also be customized to load your own files. |
homepage | |
repository | https://github.com/Jint3x/env_plus |
max_upload_size | |
id | 346679 |
size | 12,267 |
Add this to your Cargo.toml:
[dependenices]
env_plus = "0.1.2"
// This is a comment!
SECRET=YOUR_SECRET
use env_plus::EnvLoader;
fn main() {
EnvLoader::new()
.activate();
let secret = std::env::var("SECRET").unwrap();
assert_eq!(secret, String::from("YOUR_SECRET"));
}
## I want to use this style as a comment!
## == will be the new value delimiter
SECRET==YOUR_SECRET
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"));
}