Renvar

renvar is a library to deserialize environment variables into Rust data structures.

Huge thanks to softprops for envy, as this library is inspired by it and borrows much of the code from there.

Installation

Add it to your Cargo.toml

toml [dependencies] renvar = "0.1"

Usage

```rust use renvar::{fromenv, fromiter, from_str}; use serde::Deserialize; use std::env;

let env_content = r#" name=renvar type=Library dependencies=serde "#;

[derive(Debug, Deserialize, PartialEq, Eq)]

enum CrateType { Library, Binary, }

[derive(Debug, Deserialize, PartialEq, Eq)]

struct Renvar { name: String, #[serde(rename = "type")] typ: CrateType, dependencies: Vec, }

let actual = Renvar { name: "renvar".toowned(), typ: CrateType::Library, dependencies: vec!["serde".toowned()], };

// we can read from strings

let value = fromstr::(envcontent).unwrap();

assert_eq!(value, actual);

// directly from the environment

let envs = vec![ ("name".toowned(), "renvar".toowned()), ("type".toowned(), "Library".toowned()), ("dependencies".toowned(), "serde".toowned()), ];

for (key, value) in envs.clone().intoiter() { env::setvar(key, value); }

let value = from_env::().unwrap();

assert_eq!(value, actual);

// or from iterables

let value = from_iter::(envs).unwrap();

assert_eq!(value, actual); ```

Feature flags

Renvar has the following feature flags:

prefixed

prefixed gives you the prefixed function, that accepts a prefix. The prefixes will be stripped away before deserialization.

postfixed

postfix is exactly the same as prefix, just with postfixes

caseinsensitiveprefixed

Case insensitive variant of prefixed

caseinsensitivepostfixed

Case insensitive variant of postfixed

with_trimmer

Finally, the with_trimmer feature flag gives you *_with_trimmer variants for all of the above, where you can strip extraneous characters off of the beginning and end of envrironment variables by passing a closure.

Supported datatypes

Development

Tests

If you have just, you run just test, otherwise cargo test --all-features