bump version

This commit is contained in:
Dmitriy Pleshevskiy 2022-07-28 16:20:43 +03:00
parent 9ccd86ce1e
commit c4dd5d33ec
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
4 changed files with 100 additions and 34 deletions

2
Cargo.lock generated
View file

@ -4,7 +4,7 @@ version = 3
[[package]] [[package]]
name = "enve" name = "enve"
version = "0.2.0" version = "0.3.0"
dependencies = [ dependencies = [
"estring", "estring",
] ]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "enve" name = "enve"
version = "0.2.0" version = "0.3.0"
authors = ["Dmitriy Pleshevskiy <dmitriy@ideascup.me>"] authors = ["Dmitriy Pleshevskiy <dmitriy@ideascup.me>"]
description = "it helps you work with environment variables and convert it to any type using only type annotations" description = "it helps you work with environment variables and convert it to any type using only type annotations"
categories = ["config"] categories = ["config"]

View file

@ -7,7 +7,7 @@
```toml ```toml
[dependencies] [dependencies]
enve = "0.2" enve = "0.3"
``` ```
`enve` helps you work with environment variables and convert it to **any type** `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!
## Usage ## 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 ```rust
use enve::SepVec; use enve::SepVec;
type MinusVec<T> = SepVec<T, '-'>;
type PlusVec<T> = SepVec<T, '+'>; type PlusVec<T> = SepVec<T, '+'>;
type MulVec<T> = SepVec<T, '*'>; type MulVec<T> = SepVec<T, '*'>;
fn main() -> Result<(), enve::Error> { 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() .unwrap()
.iter() .iter()
.map(|p| {
p.iter()
.map(|m| m.iter().product::<f32>()) .map(|m| m.iter().product::<f32>())
.reduce(|acc, v| acc - v)
.unwrap_or_default()
})
.sum::<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(()) Ok(())
} }

View file

@ -3,41 +3,75 @@
//! `enve` helps you work with environment variables and convert it to **any type** //! `enve` helps you work with environment variables and convert it to **any type**
//! using only **type annotations**. //! 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 //! All standard environment variable types are included, but `enve` under the hood
//! uses [estring](https://github.com/pleshevskiy/estring), so you can easily create //! uses [estring](https://github.com/pleshevskiy/estring), so you can easily create
//! your own type. //! your own type.
//! //!
//! ## Getting started //! ## Usage
//!
//! Basic
//! //!
//! ```rust //! ```rust
//! use enve::SepVec;
//!
//! type MinusVec<T> = SepVec<T, '-'>;
//! type PlusVec<T> = SepVec<T, '+'>;
//! type MulVec<T> = SepVec<T, '*'>;
//!
//! fn main() -> Result<(), enve::Error> { //! fn main() -> Result<(), enve::Error> {
//! enve::sset("E", "10+5*2-3"); //! enve::sset("E", "10");
//! //!
//! let res: f32 = enve::get::<PlusVec<MinusVec<MulVec<f32>>>>("E") //! let res: f32 = enve::get("E")?;
//! .unwrap()
//! .iter()
//! .map(|p| {
//! p.iter()
//! .map(|m| m.iter().product::<f32>())
//! .reduce(|acc, v| acc - v)
//! .unwrap_or_default()
//! })
//! .sum::<f32>();
//! //!
//! println!("result: {}", res); //! println!("result: {}", res);
//! //!
//! Ok(()) //! 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 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::<PlusVec<MulVec<f32>>>("E")?
//! .iter()
//! .map(|m| m.iter().product::<f32>())
//! .sum::<f32>();
//!
//! 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. // Rustc lints.
#![forbid(unsafe_code)] #![forbid(unsafe_code)]