doc: add examples to readme

This commit is contained in:
Dmitriy Pleshevskiy 2022-07-28 14:28:09 +03:00
parent aecd3f9543
commit 039a0dd630
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
7 changed files with 82 additions and 3 deletions

View file

@ -24,6 +24,23 @@ For more details, see [examples].
## Usage
Basic
```rust
use estring::EString;
fn main() -> estring::Result<()> {
let res: i32 = EString::from("10").parse()?;
assert_eq!(res, 10);
Ok(())
}
```
You can use predefined structs like `SepVec` if you enable the `structs`
feature.
Note: You can use custom types as annotations! Just implement `ParseFragment`!
```rust
use estring::{SepVec, EString};
@ -42,8 +59,23 @@ fn main() -> estring::Result<()> {
}
```
You can use custom types as annotations! Just implement
`estring::ParseFragment`!
You can also use predefined aggregators if you enable the `aggs` feature.
```rust
use estring::{Aggregate, EString, Product, SepVec, Sum};
type PlusVec<T> = SepVec<T, '+'>;
type MulVec<T> = SepVec<T, '*'>;
fn main() -> estring::Result<()> {
let res = EString::from("10+5*2+3")
.parse::<Sum<PlusVec<Product<MulVec<f32>>>>>()?
.agg();
assert_eq!(res, 23.0);
Ok(())
}
```
## Contact Us

View file

@ -240,6 +240,7 @@ impl ParseFragment for EString {
}
}
#[cfg(feature = "aggs")]
impl Aggregatable for EString {
type Item = Self;
@ -263,6 +264,7 @@ impl ToEString for String {
}
}
#[cfg(feature = "aggs")]
impl Aggregatable for String {
type Item = Self;
@ -286,6 +288,7 @@ impl<'a> ToEString for &'a str {
}
}
#[cfg(feature = "aggs")]
impl<'a> Aggregatable for &'a str {
type Item = Self;

View file

@ -7,7 +7,23 @@
//!
//! [enve]: https://github.com/pleshevskiy/enve
//!
//! ## Getting started
//! ## Usage
//!
//! Basic
//!
//! ```rust
//! use estring::EString;
//!
//! fn main() -> estring::Result<()> {
//! let res: i32 = EString::from("10").parse()?;
//! assert_eq!(res, 10);
//! 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 estring::{SepVec, EString};
@ -27,6 +43,30 @@
//! }
//! ```
//!
//! You can also use predefined aggregators if you enable `aggs` feature.
//!
//! ```rust
//! use estring::{Aggregate, EString, Product, SepVec, Sum};
//!
//! type PlusVec<T> = SepVec<T, '+'>;
//! type MulVec<T> = SepVec<T, '*'>;
//!
//! fn main() -> estring::Result<()> {
//! let res = EString::from("10+5*2+3")
//! .parse::<Sum<PlusVec<Product<MulVec<f32>>>>>()?
//! .agg();
//!
//! assert_eq!(res, 23.0);
//! Ok(())
//! }
//! ```
//!
//! ---
//!
//! For more details, see [examples].
//!
//! [examples]: https://github.com/pleshevskiy/estring/tree/main/examples
//!
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
#![warn(missing_docs)]

View file

@ -19,6 +19,7 @@ impl ToEString for bool {
}
}
#[cfg(feature = "aggs")]
impl Aggregatable for bool {
type Item = Self;

View file

@ -19,6 +19,7 @@ macro_rules! from_env_string_numbers_impl {
}
}
#[cfg(feature = "aggs")]
impl Aggregatable for $ty {
type Item = Self;

View file

@ -25,6 +25,7 @@ where
}
}
#[cfg(feature = "aggs")]
impl<T> Aggregatable for Option<T>
where
T: Aggregatable,

View file

@ -92,6 +92,7 @@ where
}
}
#[cfg(feature = "aggs")]
impl<T, const SEP: char> Aggregatable for SepVec<T, SEP>
where
T: Aggregatable,