Compare commits
1 commit
main
...
product_ag
Author | SHA1 | Date | |
---|---|---|---|
2090bfe965 |
10 changed files with 17 additions and 97 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4,4 +4,4 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "estring"
|
||||
version = "0.3.0"
|
||||
version = "0.2.1"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "estring"
|
||||
description = "A simple way to parse a string using type annotations"
|
||||
version = "0.3.0"
|
||||
version = "0.2.1"
|
||||
edition = "2021"
|
||||
authors = ["Dmitriy Pleshevskiy <dmitriy@ideascup.me>"]
|
||||
readme = "README.md"
|
||||
|
|
38
README.md
38
README.md
|
@ -7,7 +7,7 @@
|
|||
|
||||
```toml
|
||||
[dependencies]
|
||||
estring = "0.3"
|
||||
estring = "0.2"
|
||||
```
|
||||
|
||||
A simple way to parse a string using type annotations.
|
||||
|
@ -24,23 +24,6 @@ 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};
|
||||
|
||||
|
@ -59,23 +42,8 @@ fn main() -> estring::Result<()> {
|
|||
}
|
||||
```
|
||||
|
||||
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(())
|
||||
}
|
||||
```
|
||||
You can use custom types as annotations! Just implement
|
||||
`estring::ParseFragment`!
|
||||
|
||||
## Contact Us
|
||||
|
||||
|
|
|
@ -240,7 +240,6 @@ impl ParseFragment for EString {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "aggs")]
|
||||
impl Aggregatable for EString {
|
||||
type Item = Self;
|
||||
|
||||
|
@ -264,7 +263,6 @@ impl ToEString for String {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "aggs")]
|
||||
impl Aggregatable for String {
|
||||
type Item = Self;
|
||||
|
||||
|
@ -288,7 +286,6 @@ impl<'a> ToEString for &'a str {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "aggs")]
|
||||
impl<'a> Aggregatable for &'a str {
|
||||
type Item = Self;
|
||||
|
||||
|
|
42
src/lib.rs
42
src/lib.rs
|
@ -7,23 +7,7 @@
|
|||
//!
|
||||
//! [enve]: https://github.com/pleshevskiy/enve
|
||||
//!
|
||||
//! ## 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``!
|
||||
//! ## Getting started
|
||||
//!
|
||||
//! ```rust
|
||||
//! use estring::{SepVec, EString};
|
||||
|
@ -43,30 +27,6 @@
|
|||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! 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)]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::{EString, ParseFragment, ToEString};
|
||||
use crate::core::{Aggregatable, EString, ParseFragment, ToEString};
|
||||
use crate::error::{Error, Reason};
|
||||
|
||||
impl ParseFragment for bool {
|
||||
|
@ -19,8 +19,7 @@ impl ToEString for bool {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "aggs")]
|
||||
impl crate::core::Aggregatable for bool {
|
||||
impl Aggregatable for bool {
|
||||
type Item = Self;
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::{EString, ParseFragment, ToEString};
|
||||
use crate::core::{Aggregatable, EString, ParseFragment, ToEString};
|
||||
use crate::error::{Error, Reason};
|
||||
|
||||
#[doc(hidden)]
|
||||
|
@ -19,8 +19,7 @@ macro_rules! from_env_string_numbers_impl {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "aggs")]
|
||||
impl crate::core::Aggregatable for $ty {
|
||||
impl Aggregatable for $ty {
|
||||
type Item = Self;
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::{EString, ParseFragment, ToEString};
|
||||
use crate::core::{Aggregatable, EString, ParseFragment, ToEString};
|
||||
|
||||
impl<T> ToEString for Option<T>
|
||||
where
|
||||
|
@ -25,10 +25,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "aggs")]
|
||||
impl<T> crate::core::Aggregatable for Option<T>
|
||||
impl<T> Aggregatable for Option<T>
|
||||
where
|
||||
T: crate::core::Aggregatable,
|
||||
T: Aggregatable,
|
||||
{
|
||||
type Item = T::Item;
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ hello=bar",
|
|||
#[test]
|
||||
fn should_format_pair() {
|
||||
let pair = Pair::<_, '+', _>(1, 2);
|
||||
assert_eq!(pair.to_estring(), EString(String::from("1+2")));
|
||||
assert_eq!(pair.clone().to_estring(), EString(String::from("1+2")));
|
||||
let pair_in_pair = Pair::<_, '=', _>(3, pair);
|
||||
assert_eq!(pair_in_pair.to_estring(), EString(String::from("3=1+2")));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Contains the implementations to vec type
|
||||
//!
|
||||
|
||||
use crate::core::{EString, ParseFragment, ToEString};
|
||||
use crate::core::{Aggregatable, EString, ParseFragment, ToEString};
|
||||
use std::fmt::Write;
|
||||
|
||||
/// Wrapper for ``Vec`` to split string by a separator (`SEP`).
|
||||
|
@ -92,10 +92,9 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "aggs")]
|
||||
impl<T, const SEP: char> crate::core::Aggregatable for SepVec<T, SEP>
|
||||
impl<T, const SEP: char> Aggregatable for SepVec<T, SEP>
|
||||
where
|
||||
T: crate::core::Aggregatable,
|
||||
T: Aggregatable,
|
||||
{
|
||||
type Item = T::Item;
|
||||
|
||||
|
@ -107,7 +106,6 @@ where
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::Aggregatable;
|
||||
use crate::Pair;
|
||||
use crate::{Error, Reason};
|
||||
|
||||
|
|
Reference in a new issue