You can certainly do this! An easy way might be:
That is, you can convert any
Result<T, E> into a
Future<Item=T, Error=E> easily through the
futures::done method, and then once you’ve done that you can chain on further computations like
Send + 'static bounds here are actually required by the return type,
IoFuture. This is an alias around
Box<Future<...> + Send + 'static> which is where those requirements come from. This is part of the difficulty of returning futures where if you return a trait object you have to define the
'static-ness up front.
If you were to return a concrete type (e.g.
AndThen<Done<A, io::Error>, F>) then you wouldn’t require either
'static. Additionally, if you were to use
impl Future you also wouldn’t require the bounds. You also optionally have the ability to return a non-
Send trait object or even a non-
'static one depending on what you’d like to do in this situation.
Lemme know if any of that’s confusing though, I may need to update the “returning futures” section of the tutorial in light of recent changes with the futures library