agg: fix typo, add docs
This commit is contained in:
parent
e9f77c203f
commit
af55a8a31e
6 changed files with 27 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use crate::{Aggregate, Aggregateble, EString, ParseFragment};
|
use crate::{Aggregatable, Aggregate, EString, ParseFragment};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
struct Sum<R, T>(T, PhantomData<R>);
|
struct Sum<R, T>(T, PhantomData<R>);
|
||||||
|
@ -23,7 +23,7 @@ where
|
||||||
impl<R, T> Aggregate for Sum<R, T>
|
impl<R, T> Aggregate for Sum<R, T>
|
||||||
where
|
where
|
||||||
R: std::iter::Sum,
|
R: std::iter::Sum,
|
||||||
T: Aggregateble<Item = R>,
|
T: Aggregatable<Item = R>,
|
||||||
{
|
{
|
||||||
type Target = R;
|
type Target = R;
|
||||||
|
|
||||||
|
@ -32,10 +32,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, T> Aggregateble for Sum<R, T>
|
impl<R, T> Aggregatable for Sum<R, T>
|
||||||
where
|
where
|
||||||
R: std::iter::Sum,
|
R: std::iter::Sum,
|
||||||
T: Aggregateble<Item = R>,
|
T: Aggregatable<Item = R>,
|
||||||
{
|
{
|
||||||
type Item = R;
|
type Item = R;
|
||||||
|
|
||||||
|
|
15
src/core.rs
15
src/core.rs
|
@ -123,9 +123,13 @@ pub trait Aggregate {
|
||||||
fn agg(self) -> Self::Target;
|
fn agg(self) -> Self::Target;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Aggregateble {
|
// TODO: add example
|
||||||
|
/// Trait to represent structures that can iterate values for the aggregator.
|
||||||
|
pub trait Aggregatable {
|
||||||
|
/// The type of the elements being iterated over.
|
||||||
type Item;
|
type Item;
|
||||||
|
|
||||||
|
/// Returns Vec of aggregatable values
|
||||||
fn items(self) -> Vec<Self::Item>;
|
fn items(self) -> Vec<Self::Item>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,9 +240,10 @@ impl ParseFragment for EString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Aggregateble for EString {
|
impl Aggregatable for EString {
|
||||||
type Item = Self;
|
type Item = Self;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn items(self) -> Vec<Self::Item> {
|
fn items(self) -> Vec<Self::Item> {
|
||||||
vec![self]
|
vec![self]
|
||||||
}
|
}
|
||||||
|
@ -258,9 +263,10 @@ impl ToEString for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Aggregateble for String {
|
impl Aggregatable for String {
|
||||||
type Item = Self;
|
type Item = Self;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn items(self) -> Vec<Self::Item> {
|
fn items(self) -> Vec<Self::Item> {
|
||||||
vec![self]
|
vec![self]
|
||||||
}
|
}
|
||||||
|
@ -280,9 +286,10 @@ impl<'a> ToEString for &'a str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Aggregateble for &'a str {
|
impl<'a> Aggregatable for &'a str {
|
||||||
type Item = Self;
|
type Item = Self;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn items(self) -> Vec<Self::Item> {
|
fn items(self) -> Vec<Self::Item> {
|
||||||
vec![self]
|
vec![self]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::core::{Aggregateble, EString, ParseFragment, ToEString};
|
use crate::core::{Aggregatable, EString, ParseFragment, ToEString};
|
||||||
use crate::error::{Error, Reason};
|
use crate::error::{Error, Reason};
|
||||||
|
|
||||||
impl ParseFragment for bool {
|
impl ParseFragment for bool {
|
||||||
|
@ -19,9 +19,10 @@ impl ToEString for bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Aggregateble for bool {
|
impl Aggregatable for bool {
|
||||||
type Item = Self;
|
type Item = Self;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn items(self) -> Vec<Self::Item> {
|
fn items(self) -> Vec<Self::Item> {
|
||||||
vec![self]
|
vec![self]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::core::{Aggregateble, EString, ParseFragment, ToEString};
|
use crate::core::{Aggregatable, EString, ParseFragment, ToEString};
|
||||||
use crate::error::{Error, Reason};
|
use crate::error::{Error, Reason};
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -19,9 +19,10 @@ macro_rules! from_env_string_numbers_impl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Aggregateble for $ty {
|
impl Aggregatable for $ty {
|
||||||
type Item = Self;
|
type Item = Self;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn items(self) -> Vec<Self::Item> {
|
fn items(self) -> Vec<Self::Item> {
|
||||||
vec![self]
|
vec![self]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::core::{Aggregateble, EString, ParseFragment, ToEString};
|
use crate::core::{Aggregatable, EString, ParseFragment, ToEString};
|
||||||
|
|
||||||
impl<T> ToEString for Option<T>
|
impl<T> ToEString for Option<T>
|
||||||
where
|
where
|
||||||
|
@ -25,9 +25,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Aggregateble for Option<T>
|
impl<T> Aggregatable for Option<T>
|
||||||
where
|
where
|
||||||
T: Aggregateble,
|
T: Aggregatable,
|
||||||
{
|
{
|
||||||
type Item = T::Item;
|
type Item = T::Item;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Contains the implementations to vec type
|
//! Contains the implementations to vec type
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use crate::core::{Aggregateble, EString, ParseFragment, ToEString};
|
use crate::core::{Aggregatable, EString, ParseFragment, ToEString};
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
/// Wrapper for ``Vec`` to split string by a separator (`SEP`).
|
/// Wrapper for ``Vec`` to split string by a separator (`SEP`).
|
||||||
|
@ -92,9 +92,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, const SEP: char> Aggregateble for SepVec<T, SEP>
|
impl<T, const SEP: char> Aggregatable for SepVec<T, SEP>
|
||||||
where
|
where
|
||||||
T: Aggregateble,
|
T: Aggregatable,
|
||||||
{
|
{
|
||||||
type Item = T::Item;
|
type Item = T::Item;
|
||||||
|
|
||||||
|
|
Reference in a new issue