Crate jealousy

source ·
Expand description

jealousy is a wrapper crate around the envy crate. It doesn’t add much on top of it, but rather gives a simple Trait that can be implemented or a derive Macro, for even easier use.

This crate additionally adds logging around envy, using the log crate. This makes it easier to debug in production environments.

Usage

Using the trait

use jealousy::FromEnv;
use serde::Deserialize;

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

// no need for changing the default impl, unless you need different
// logging logic.
impl FromEnv for Config {
    const PREFIX: &'static str = "APP";
}

Using the derive Macro

To use the derive macro, you have to enable the derive feature

use jealousy::FromEnv;
use serde::Deserialize;

#[derive(Deserialize, FromEnv)]
#[from_env(prefix = "APP")]
struct Config {
    some_var: String
}

Enums

  • Types of errors that may result from failed attempts to deserialize a type from env vars

Traits

Derive Macros