Expand description
§kankyo
kankyo is a crate for the loading and unloading of .env files or other
readers into and from the environment.
This crate is meant to be a more modular and efficient, yet concise collection of functions exposed for any custom requirement. Due to its design, it is applicable in both synchronous and asynchronous applications.
§Installation
This library requires at least Rust 1.0.0.
Add the following dependency to your project’s Cargo.toml:
kankyo = "0.3"§What are .env files?
Environment variable files, often named .env, are files usually located at
the project root. The contents of the file are = (equals sign)-delimited
lines of key-value pairs. A sample file might look like:
DEBUG=info
DB_HOST=127.0.0.1 # This is a comment, not parsed as part of the value.
# Empty lines are ignored, as are lines solely consisting of a comment.The library works with interfacing over readers (types implementing the
std::io::Read trait), meaning that you can pass slices of bytes, strings,
files, etc. to it.
For example, opening a file and parsing its contents into the environment, overwriting existing variables:
extern crate kankyo;
use std::fs::File;
let mut file = try!(File::open("./.env"));
try!(kankyo::load_from_reader(&mut file, true));
println!("Loaded!");Due to the common nature of this operation, a function that does precisely this is offered:
extern crate kankyo;
try!(kankyo::init());
println!("Loaded!");Modules§
- utils
- A collection of lower-level functions for parsing .env files, unloading keys, and working with parsed .env lines.
Functions§
- init
- Loads a
.envfile at the current working directory (./.env), overwriting existing variables. - key
- Loads a key from the current environment. This is more or less an alias of
std::env::var, but the benefit - slightly - is one less possible use statement. - load
- Loads a
.envfile at the current working directory (./.env). - load_
from_ path - Reads the content of a file at a given path to find
.envlines. - load_
from_ reader - Reads the content of a reader and parses it to find
.envlines. - snapshot
- Creates a snapshot of the present environment variables.
- unload
- Unloads all environment variables in the default
./.envfile from the current environment. - unload_
from_ path - Unloads from the read content of the given path.
- unload_
from_ reader - Unloads from the read content of the given reader.