#env-var #toml-config #configuration-management #variables #environment #validation #inventory

env-inventory

A simple library to load globally available environment variables into a static inventory

3 releases

0.2.3 Sep 28, 2023
0.2.2 Sep 28, 2023
0.1.1 Sep 20, 2023

#720 in Configuration

31 downloads per month

MIT license

22KB
270 lines

Env-Inventory: Environment Variable Management

env-inventory is a Rust library designed to manage and consolidate the process of fetching parameters from the environment. It offers a flexible system to work with environment variables and configurations stored in TOML files.

Features

  • 🌍 Unified Access: Streamline the way parameters are fetched from the environment.
  • 📁 TOML Support: Read and merge configurations directly from TOML files, allowing hierarchical configurations.
  • Validation: Validate and ensure that required environment variables are set.

Getting Started

Installation

Add env-inventory to your Cargo.toml:

[dependencies]
env-inventory = "0.2" # Check crates.io for the latest version

Usage

  1. Define required environment variables using the RequiredVar struct.
env_inventory::register!("DATABASE_URL");
  1. Load and validate environment variables from your TOML configurations:
let paths = ["path/to/settings.toml"];
env_inventory::load_and_validate_env_vars(&paths, "env").unwrap();

Error Handling

The library provides an EnvInventoryError enum to handle various error types such as:

  • Reading or parsing the settings file.
  • Missing required environment variables.

Contributing

Pull requests are welcome. Please ensure that your PR passes all the tests before submitting. Unless otherwise stated, your contributions are assumed to be under the MIT license.

License

MIT

Dependencies

~0.8–1.5MB
~31K SLoC