envro

Crates.ioenvro
lib.rsenvro
version0.4.0
sourcesrc
created_at2024-02-27 17:39:50.081542
updated_at2024-11-13 13:26:26.294189
descriptionA crate to load environment variables from a .env file into the process environment variables
homepage
repository
max_upload_size
id1155298
size15,490
Simone Sanfratello (simone-sanfratello)

documentation

README

Envro

A crate to load environment variables from a .env file into the process environment variables

Getting started

cargo add envro
use std::env;

use envro::*;

fn main() {
    let env_file = env::current_dir().unwrap().join(".env-sample");

    // load env vars and return them
    let env_vars = load_dotenv(&env_file).unwrap();
    println!("---");
    println!(">> vars from .env file");
    println!("{:#?}", &env_vars);

    // load env vars into env::vars
    load_dotenv_in_env_vars(&env_file).unwrap();
    println!("---");
    println!(">> from env::vars()");
    for (key, value) in env::vars() {
        if !env_vars.contains_key(&key) {
            continue;
        }
        println!("{key}: {value}");
    }
}

Test

cargo test

TODO

  • check .evn file contains vars only once
  • support multiline string values
  • values validation
  • github action publish
  • coerce env vars to types
  • test, code coverage

LICENSE

MIT License

Copyright (c) 2024 Simone Sanfratello

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Commit count: 0

cargo fmt