4 releases

0.1.3 Apr 13, 2022
0.1.2 Apr 11, 2022
0.1.1 Apr 11, 2022
0.1.0 Apr 10, 2022

#584 in Configuration

Custom license

7KB
71 lines

Rust

envloader

Simple environment loader/setter that loads desired env variables from a file and inserts them into the runtime environment.

use cases

Running an application that relies on environment variables locally by simply having those variables in a file instead of setting your system environment every time.

installing

Add envloader = "0.1.3" to cargo.toml

crates.io

https://crates.io/crates/envloader

docs

https://docs.rs/envloader


lib.rs:

Simple Environment variable setter which loads a specified file, reads the key value pairs from each new line, and inserts them into the runtime environment. example:

EnvironmentLoader::new(file_path.to_str().unwrap());

Where file_path is a &str path to the desired env to load, and its content is as follows:

 E1=123
 E2=ABC

The result would be environment variables (E1, E2) being set with the specified values after the first = sign.

A code snippet example for a use case:

use std::{fmt::Result, fs::metadata};

let config_path = "config/server.env";
match metadata(config_path) {
Ok(_) => envloader::EnvironmentLoader::new(config_path),
Err(_) => println!("Using system environment"),
}

No runtime deps