I am trying to write a simple TCP client in Rust using Tokio crate. My code is pretty close to this example minus the TLS:
extern crate futures;
extern crate
Unfortunately the answer here is quite specific, but the question turns up for any kind of search for:
the trait
futures::Futureis not implemented for()
A typical scenario for this kind of error is:
foo.then(|stream| {
// ... Do random things here
final_statement();
});
This causes an error because the majority of the extension functions require the return type to implement IntoFuture. However, () does not implement IntoFuture, and by terminating the block with a ; the implicit return type is ().
However, IntoFuture is implemented for Option and Result.
Rather than just randomly removing semicolons vaguely in the hope this will somehow magically make your code compile, consider:
You should be returning something that can be converted into a Future using IntoFuture.
If you don't have a specific promise that you're returning, consider returning Ok(()) to say simply 'this is done' from your callback:
foo.then(|stream| {
// ... Do random things here
final_statement();
return Ok(()); // <-- Result(()) implements `IntoFuture`.
});
Note specifically I terminate this block with an explicit return statement; this is deliberate. This is a typical example of how the ergonomics of 'can omit semicolon to implicitly return object' is tangibly harmful; terminating the block with Ok(()); will continue to fail with the same error.