Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
pleshevskiy committed Jul 29, 2022
1 parent 9ccd86c commit c4dd5d3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "enve"
version = "0.2.0"
version = "0.3.0"
authors = ["Dmitriy Pleshevskiy <[email protected]>"]
description = "it helps you work with environment variables and convert it to any type using only type annotations"
categories = ["config"]
Expand Down
54 changes: 43 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

```toml
[dependencies]
enve = "0.2"
enve = "0.3"
```

`enve` helps you work with environment variables and convert it to **any type**
Expand All @@ -25,28 +25,60 @@ Look at the [examples] to see the power!

## Usage

Basic

```rust
fn main() -> Result<(), enve::Error> {
enve::sset("E", "10");

let res: f32 = enve::get("E")?;

println!("result: {}", res);

Ok(())
}
```

You can use predefined structs like `SepVec` if you enable `structs` feature.

Note: You can use custom types as annotations! Just implement `ParseFragment`.

```rust
use enve::SepVec;

type MinusVec<T> = SepVec<T, '-'>;
type PlusVec<T> = SepVec<T, '+'>;
type MulVec<T> = SepVec<T, '*'>;

fn main() -> Result<(), enve::Error> {
enve::sset("E", "10+5*2-3");
enve::sset("E", "10+5*2+3");

let res: f32 = enve::get::<PlusVec<MinusVec<MulVec<f32>>>>("E")
let res: f32 = enve::get::<PlusVec<MulVec<f32>>>("E")
.unwrap()
.iter()
.map(|p| {
p.iter()
.map(|m| m.iter().product::<f32>())
.reduce(|acc, v| acc - v)
.unwrap_or_default()
})
.map(|m| m.iter().product::<f32>())
.sum::<f32>();

println!("result: {}", res);
assert_eq!(res, 23.0);

Ok(())
}
```

You can also use predefined aggregators if you enable `aggs` feature.

```rust
use enve::{SepVec, Product, Sum, estring::Aggregate};

type PlusVec<T> = SepVec<T, '+'>;
type MulVec<T> = SepVec<T, '*'>;

fn main() -> Result<(), enve::Error> {
enve::sset("E", "10+5*2+3");

let res: f32 = enve::get::<Sum<PlusVec<Product<MulVec<f32>>>>>("E")?
.agg();

assert_eq!(res, 23.0);

Ok(())
}
Expand Down
64 changes: 49 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,75 @@
//! `enve` helps you work with environment variables and convert it to **any type**
//! using only **type annotations**.
//!
//! Look at the [examples](https://github.com/pleshevskiy/enve/tree/main/examples)
//! to see the power!
//!
//! All standard environment variable types are included, but `enve` under the hood
//! uses [estring](https://github.com/pleshevskiy/estring), so you can easily create
//! your own type.
//!
//! ## Getting started
//! ## Usage
//!
//! Basic
//!
//! ```rust
//! fn main() -> Result<(), enve::Error> {
//! enve::sset("E", "10");
//!
//! let res: f32 = enve::get("E")?;
//!
//! println!("result: {}", res);
//!
//! Ok(())
//! }
//! ```
//!
//! You can use predefined structs like `SepVec` if you enable `structs` feature.
//!
//! Note: You can use custom types as annotations! Just implement `ParseFragment`.
//!
//! ```rust
//! use enve::SepVec;
//!
//! type MinusVec<T> = SepVec<T, '-'>;
//! type PlusVec<T> = SepVec<T, '+'>;
//! type MulVec<T> = SepVec<T, '*'>;
//!
//! fn main() -> Result<(), enve::Error> {
//! enve::sset("E", "10+5*2-3");
//! enve::sset("E", "10+5*2+3");
//!
//! let res: f32 = enve::get::<PlusVec<MinusVec<MulVec<f32>>>>("E")
//! .unwrap()
//! let res = enve::get::<PlusVec<MulVec<f32>>>("E")?
//! .iter()
//! .map(|p| {
//! p.iter()
//! .map(|m| m.iter().product::<f32>())
//! .reduce(|acc, v| acc - v)
//! .unwrap_or_default()
//! })
//! .map(|m| m.iter().product::<f32>())
//! .sum::<f32>();
//!
//! println!("result: {}", res);
//! assert_eq!(res, 23.0);
//!
//! Ok(())
//! }
//! ```
//!
//! You can also use predefined aggregators if you enable `aggs` feature.
//!
//! ```rust
//! use enve::{SepVec, Product, Sum, estring::Aggregate};
//!
//! type PlusVec<T> = SepVec<T, '+'>;
//! type MulVec<T> = SepVec<T, '*'>;
//!
//! fn main() -> Result<(), enve::Error> {
//! enve::sset("E", "10+5*2+3");
//!
//! let res = enve::get::<Sum<PlusVec<Product<MulVec<f32>>>>>("E")?.agg();
//!
//! assert_eq!(res, 23.0);
//!
//! Ok(())
//! }
//! ```
//!
//! ---
//!
//! Look at the [examples] to see the power!
//!
//! [examples]: https://github.com/pleshevskiy/enve/tree/main/examples
//!
// Rustc lints.
#![forbid(unsafe_code)]
Expand Down

0 comments on commit c4dd5d3

Please sign in to comment.