Trait frunk::coproduct::CoproductFoldable [] [src]

pub trait CoproductFoldable<Folder, Output> {
    fn fold(self, f: Folder) -> Output;
}

Trait for implementing "folding" a Coproduct into a value.

The Folder should be an HList of closures that correspond (in order, for now..) to the types used in declaring the Coproduct type.

Example

type I32StrBool = Coprod!(i32, f32, bool);

let co1: I32StrBool = into_coproduct(3);
let co2: I32StrBool = into_coproduct(true);
let co3: I32StrBool = into_coproduct(42f32);

let folder = hlist![|&i| format!("int {}", i),
                    |&f| format!("float {}", f),
                    |&b| (if b { "t" } else { "f" }).to_string()];

assert_eq!(co1.as_ref().fold(folder), "int 3".to_string());Run

Required Methods

Implementors