2 releases
Uses old Rust 2015
0.1.1 | Aug 23, 2015 |
---|---|
0.1.0 | Aug 6, 2015 |
#16 in #either
Used in stack
8KB
110 lines
coalesce
coalesce
allows for easy unification of disjoint types, often useful for combining multiple
concrete instances into a common trait object. You can run an arbitrary code block over each
item, see the API docs for example usage.
lib.rs
:
Coalesce allows you to unify disjoint types on the stack.
It is often useful to return different implementations of a common trait such as
Iterator
or Read
from conditional branches. The coalesce!
macro makes it
easy to unify them into a common trait object:
#[macro_use]
extern crate coalesce;
use coalesce::Coalesce2;
use std::iter::repeat;
let mut i = if some_condition() {
Coalesce2::A(repeat(5u32).take(2))
} else {
Coalesce2::B(0u32..8)
};
let i = coalesce!(2 => |ref mut i| i as &mut Iterator<Item=u32>);
for x in i {
println!("{}", x);
}