Crate coalesce [] [src]

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);
}

Macros

coalesce!

Coalesces multiple values into one common (often borrowed) type.

Enums

Coalesce0
Coalesce1
Coalesce2
Coalesce3
Coalesce4
Coalesce5
Coalesce6
Coalesce7
Coalesce8
Coalesce9