Skip to main content

Crate rust_env

Crate rust_env 

Source
Expand description

§rust-env

rust-env is a lightweight environment configuration library for Rust.

It helps you manage .env-style configuration files with support for:

  • Key-value pairs
  • Vector (list) values using ; separators
  • Runtime OS environment variables
  • Reading and writing environment files

§Features

  • Parse .env files into structured data
  • Support for string and vector values
  • Access local and global environment variables
  • Modify and persist environment files
  • Simple helper API for extracting values

§Value Model

Internally, rust-env represents data using:

  • Str(key, value)
  • Vec(key, Vec<String>)
  • Comment(String)

§Example

use rust_env::Env;

let mut env = Env::new("./.env");

let port = env.get_pair("PORT");
env.set(Str("PORT", "8080"));

§Local vs Global

  • Local: values loaded from .env file
  • Global: OS environment variables

When using merged lookup:

global > local

§Notes

  • All values are stored as strings internally
  • Vector values are separated using ;
  • File writes occur immediately when using set

§Version History

§v0.2.0

  • Added match_str and match_vec helpers
  • Refactored codebase into multiple files
  • Fixed 3 known bugs

§Experimental

Experimental features such as a future markup language (RML) are not part of this crate.

They may be developed separately in the future.

Structs§

Env
The main environment container used by rust-env.

Enums§

Pair
Wrapper
This enum mainly rap two type of data String and Vec<String> See docs of struct Env of this package for learn more

Traits§

EnvFrame
A trait that defines the core behavior of an environment system.

Functions§

Str
get_d
match_str
On version 0.2.0 of rust-env DX improved You don’t need to match a Wrapper variant Instead use match_str and match vec Here’s a example
match_vec
On version 0.2.0 of rust-env DX improved You don’t need to match a Wrapper variant Instead use match_str and match vec Here’s a example