Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save drorlevywork/2bfea00d0ff5cdbe454ea077f4ee659c to your computer and use it in GitHub Desktop.
Save drorlevywork/2bfea00d0ff5cdbe454ea077f4ee659c to your computer and use it in GitHub Desktop.
more details
fn sometestbox(
c: future::Loop<u32, u32>,
) -> Box<Future<Item = future::Loop<u32, u32>, Error = u32> + Send> {
if let future::Loop::Continue(i) = c {
let delay = Instant::now().add(Duration::from_secs(1));
Box::new(
Delay::new(delay)
.map(move |_| future::Loop::Continue(i))
.map_err(|_| 1)
)
} else {
Box::new(future::ok(c))
}
}
//this one does not compile
//giving the error:
// `if let` arms have incompatible types
//expected struct `futures::MapErr`, found struct `futures::FutureResult`
//note: expected type `futures::MapErr<futures::Map<tokio::timer::Delay, [closure@src/bin/main.rs:84:18: 84:52 i:_]>, [closure@src/bin/main.rs:85:22: 85:27]>`
// found type `futures::FutureResult<futures::future::Loop<u32, u32>, _>`
fn sometest(
c: future::Loop<u32, u32>,
) -> impl Future<Item = future::Loop<u32, u32>, Error = u32> {
if let future::Loop::Continue(i) = c {
let delay = Instant::now().add(Duration::from_secs(1));
Delay::new(delay)
.map(move |_| future::Loop::Continue(i))
.map_err(|_| 1)
} else {
future::ok(c)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment