Sun Feb 15 18:43:40 EST 2015

trait objects

Composing iterators from higher order functions works well, as long as
you keep them "inside" a function.

        // expand data word into bits FIXME: add frame strobe, polarities
                  (0..nb_bits).flat_map(move |shift| {
                      let bit = (data >> (nb_bits - 1 - shift)) & 1;
                      // expand bit into clocked bit sequence
                      (0..2).map(move |clock|
                                 (clock << c.clock_channel) |
                                 (bit   << c.data_channel))
        // oversample
                  (0..period).map(move |_| bus)))

Trying to turn them into trait objects becomes problematic[1]:

    You can't put anything meaningful in **what goes here**. The
    closure you define has a compiler-generated type that you can't
    name (that is, until abstract return types are implemented).

Creating an iterator object should be possible if the closures are
boxed as well, but requires a wrapper struct for the Fn trait so at
this point, the simplest way to reuse that code is to make a macro.

[1] https://stackoverflow.com/questions/27496278/how-to-return-a-generic-map-struct