4 releases

0.2.2 Apr 17, 2023
0.2.1 Apr 14, 2023
0.2.0 Apr 14, 2023
0.1.0 Jul 22, 2022

#3 in #desired-type

Download history 18/week @ 2023-10-31 9/week @ 2023-11-07 25/week @ 2023-11-14 46/week @ 2023-11-21 22/week @ 2023-11-28 14/week @ 2023-12-05 7/week @ 2023-12-12 56/week @ 2023-12-19 19/week @ 2023-12-26 10/week @ 2024-01-02 9/week @ 2024-01-09 27/week @ 2024-01-16 7/week @ 2024-01-23 29/week @ 2024-01-30 8/week @ 2024-02-06 32/week @ 2024-02-13

95 downloads per month
Used in 2 crates

MIT license

15KB
336 lines

envir

Github actions Gitlab CI

A toolbox to deal with your environment.

Basics

Without feature, this crate provide simple functions to retreive the value of an environment variable:

  • get to retreive as string;
  • parse to directly parse the value as a desired type.

The try_ version of theire functions return None if the variable doens’t exist when get and parse return an Error::Missing error.

In addition this crate provide a set function, like std::env::set_var but works for all types implement ToString.

Finally, a collect function to retreive all environment variables in a easy to print collection.

dotenv

The dotenv feature adds an eponyme function to load .env file.

serde

The serde feature adds macro to deserialize struct from env:

#[derive(envir::Deserialize)]
struct Config {
}

let config = envir::from_env()?;
// or
let config = Config::from_env()?;

And serialize to env:

#[derive(envir::Serialize, Default)]
struct Config {
}

let config = Config::default();
config.export();

The extrapolation feature allows environment variables replacement in the default macro attribute:

#[derive(envir::Deserialize)]
struct Config {
    #[envir(defaut = "/home/${USER}")]
    home: String,
}

You can read the envir_derive crate documentation for more informations.

Dependencies

~0–630KB
~11K SLoC