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

Commit c4dd5d3

Browse files
committed
bump version
1 parent 9ccd86c commit c4dd5d3

File tree

4 files changed

+94
-28
lines changed

4 files changed

+94
-28
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "enve"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["Dmitriy Pleshevskiy <[email protected]>"]
55
description = "it helps you work with environment variables and convert it to any type using only type annotations"
66
categories = ["config"]

README.md

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
```toml
99
[dependencies]
10-
enve = "0.2"
10+
enve = "0.3"
1111
```
1212

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

2626
## Usage
2727

28+
Basic
29+
30+
```rust
31+
fn main() -> Result<(), enve::Error> {
32+
enve::sset("E", "10");
33+
34+
let res: f32 = enve::get("E")?;
35+
36+
println!("result: {}", res);
37+
38+
Ok(())
39+
}
40+
```
41+
42+
You can use predefined structs like `SepVec` if you enable `structs` feature.
43+
44+
Note: You can use custom types as annotations! Just implement `ParseFragment`.
45+
2846
```rust
2947
use enve::SepVec;
3048

31-
type MinusVec<T> = SepVec<T, '-'>;
3249
type PlusVec<T> = SepVec<T, '+'>;
3350
type MulVec<T> = SepVec<T, '*'>;
3451

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

38-
let res: f32 = enve::get::<PlusVec<MinusVec<MulVec<f32>>>>("E")
55+
let res: f32 = enve::get::<PlusVec<MulVec<f32>>>("E")
3956
.unwrap()
4057
.iter()
41-
.map(|p| {
42-
p.iter()
43-
.map(|m| m.iter().product::<f32>())
44-
.reduce(|acc, v| acc - v)
45-
.unwrap_or_default()
46-
})
58+
.map(|m| m.iter().product::<f32>())
4759
.sum::<f32>();
4860

49-
println!("result: {}", res);
61+
assert_eq!(res, 23.0);
62+
63+
Ok(())
64+
}
65+
```
66+
67+
You can also use predefined aggregators if you enable `aggs` feature.
68+
69+
```rust
70+
use enve::{SepVec, Product, Sum, estring::Aggregate};
71+
72+
type PlusVec<T> = SepVec<T, '+'>;
73+
type MulVec<T> = SepVec<T, '*'>;
74+
75+
fn main() -> Result<(), enve::Error> {
76+
enve::sset("E", "10+5*2+3");
77+
78+
let res: f32 = enve::get::<Sum<PlusVec<Product<MulVec<f32>>>>>("E")?
79+
.agg();
80+
81+
assert_eq!(res, 23.0);
5082

5183
Ok(())
5284
}

src/lib.rs

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,75 @@
33
//! `enve` helps you work with environment variables and convert it to **any type**
44
//! using only **type annotations**.
55
//!
6-
//! Look at the [examples](https://github.com/pleshevskiy/enve/tree/main/examples)
7-
//! to see the power!
8-
//!
96
//! All standard environment variable types are included, but `enve` under the hood
107
//! uses [estring](https://github.com/pleshevskiy/estring), so you can easily create
118
//! your own type.
129
//!
13-
//! ## Getting started
10+
//! ## Usage
11+
//!
12+
//! Basic
13+
//!
14+
//! ```rust
15+
//! fn main() -> Result<(), enve::Error> {
16+
//! enve::sset("E", "10");
17+
//!
18+
//! let res: f32 = enve::get("E")?;
19+
//!
20+
//! println!("result: {}", res);
21+
//!
22+
//! Ok(())
23+
//! }
24+
//! ```
25+
//!
26+
//! You can use predefined structs like `SepVec` if you enable `structs` feature.
27+
//!
28+
//! Note: You can use custom types as annotations! Just implement `ParseFragment`.
1429
//!
1530
//! ```rust
1631
//! use enve::SepVec;
1732
//!
18-
//! type MinusVec<T> = SepVec<T, '-'>;
1933
//! type PlusVec<T> = SepVec<T, '+'>;
2034
//! type MulVec<T> = SepVec<T, '*'>;
2135
//!
2236
//! fn main() -> Result<(), enve::Error> {
23-
//! enve::sset("E", "10+5*2-3");
37+
//! enve::sset("E", "10+5*2+3");
2438
//!
25-
//! let res: f32 = enve::get::<PlusVec<MinusVec<MulVec<f32>>>>("E")
26-
//! .unwrap()
39+
//! let res = enve::get::<PlusVec<MulVec<f32>>>("E")?
2740
//! .iter()
28-
//! .map(|p| {
29-
//! p.iter()
30-
//! .map(|m| m.iter().product::<f32>())
31-
//! .reduce(|acc, v| acc - v)
32-
//! .unwrap_or_default()
33-
//! })
41+
//! .map(|m| m.iter().product::<f32>())
3442
//! .sum::<f32>();
3543
//!
36-
//! println!("result: {}", res);
44+
//! assert_eq!(res, 23.0);
3745
//!
3846
//! Ok(())
3947
//! }
4048
//! ```
49+
//!
50+
//! You can also use predefined aggregators if you enable `aggs` feature.
51+
//!
52+
//! ```rust
53+
//! use enve::{SepVec, Product, Sum, estring::Aggregate};
54+
//!
55+
//! type PlusVec<T> = SepVec<T, '+'>;
56+
//! type MulVec<T> = SepVec<T, '*'>;
57+
//!
58+
//! fn main() -> Result<(), enve::Error> {
59+
//! enve::sset("E", "10+5*2+3");
60+
//!
61+
//! let res = enve::get::<Sum<PlusVec<Product<MulVec<f32>>>>>("E")?.agg();
62+
//!
63+
//! assert_eq!(res, 23.0);
64+
//!
65+
//! Ok(())
66+
//! }
67+
//! ```
68+
//!
69+
//! ---
70+
//!
71+
//! Look at the [examples] to see the power!
72+
//!
73+
//! [examples]: https://github.com/pleshevskiy/enve/tree/main/examples
74+
//!
4175
4276
// Rustc lints.
4377
#![forbid(unsafe_code)]

0 commit comments

Comments
 (0)