Semigroup trait is useful for combining multiple elements.
For example:
This crate enables you to derive Semigroup
and provides many practical implementations.
Usage
Examples
A CLI example of clap and serde integration, see https://github.com/hayas1/semigroup/blob/master/semigroup/examples/clap_serde.rs
Simple coalesce
use Semigroup;
let cli = Config ;
let file = Config ;
let env = Config ;
let config = cli.semigroup.semigroup;
assert_eq!;
Coalesce with rich enum annotation and lazy evaluation
More detail is in [Annotate] and [Lazy].
use ;
let cli = Config .annotated;
let file = Config .annotated;
let env = Config .annotated;
let lazy = from.semigroup.semigroup;
assert_eq!;
assert_eq!;
let config = lazy.combine;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Highlights
#[derive(Semigroup)]and#[derive(Construction)]- derive [
Semigroup] implements semigroup for a struct by field level semantics. - derive [
Construction] defines a new semigroup operation (Some operations are already defined in [crate::op]).
- derive [
- Practical annotation support
- Some semigroup operations such as [
op::Coalesce] can have an annotation that is represented by [Annotate] trait.
- Some semigroup operations such as [
- Combine multiple elements
- [
CombineIterator] provides fold and combine operations for iterators. - [
Lazy] provides lazy evaluation. - [
segment_tree::SegmentTree] is useful for fast range queries on [Monoid].
- [
[Semigroup] |
[Annotate] |
[Monoid] |
[Commutative] |
|
|---|---|---|---|---|
| property | associativity | annotation | identity element | commutativity |
#[derive(Semigroup)] #[semigroup(...)] |
annotated |
monoid |
commutative |
|
#[derive(Construction)] #[construction(...)] |
annotated |
monoid |
commutative |
|
| testing | [assert_semigroup!] |
[assert_monoid!] |
[assert_commutative!] |
|
| typical combiner | [CombineIterator] |
[Lazy] |
SegmentTree |
[CombineStream] |
Links
- GitHub: https://github.com/hayas1/semigroup
- GitHub Pages: https://hayas1.github.io/semigroup/semigroup
- Release Notes: https://github.com/hayas1/semigroup/releases
- Crates.io: https://crates.io/crates/semigroup
- Docs.rs: https://docs.rs/semigroup
Testing
Benchmarks
// TODO
Coverage
https://hayas1.github.io/semigroup/semigroup/tarpaulin-report.html