How can I store the result of a future where map_err has been chained?

I have a future that I’m trying to store in a custom combinator. It’s always the same type: tokio::timer::Delay with an error mapped to () (for simplicity’s sake, though I may want to change this later).

let expire = Delay::new(expiry_time)
                  .map_err(|_| ());

I don’t know how to store this. Its type is MapErr<Delay, [closure]>, and when I try to box the closure, it won’t work with the map_err function.

The easiest way is to put it on the heap, giving it the type Box<Future<Item=(), Error=()>>. See:

Oh sorry, should have read more closely that you already tried boxing, but you just tried boxing the closure. Try boxing the whole future, unless there’s a reason not to do that.

Can also store it in MapErr<Delay, fn(Error)> if you need to name the type.

1 Like

Box<Future<Item=(), Error=()>> ended up working out well! I think I had tried boxing the whole future, but I hadn’t specified some of the types correctly.

1 Like