Hi,
I am building an application which will connect to multiple servers. For now it just connect to one.
Sadly, I am getting this error:
> error: no method named and_then
found for type tokio_core::net::TcpStreamNew
in the current scope
--> src/main.rs:49:26 | 49 | let connect = socket.and_then(|socket| { | ^^^^^^^^ |
= note: the method
and_then
exists but the following trait bounds were not satisfied:tokio_core::net::TcpStreamNew : futures::Future
= help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add ause
for it:
= help: candidate #1:use futures::future::Future;
This is my code:
use tokio_core::reactor::Core;
use tokio_core::net::TcpStream;
use futures::future::Future;
fn main() {
let mut l = Core::new().unwrap();
let handle = l.handle();
let config = Config::init("config.toml".to_string()).unwrap();
let addr: Vec<SocketAddr> = config.peers.iter().map(|x| x.node_addr.parse().unwrap()).collect();
let local: SocketAddr = "127.0.0.1:9000".parse().unwrap();
// later connect to multiple servers
let socket = TcpStream::connect(&local, &handle);
let connect = socket.and_then(|socket| {
// TODO something
});
l.run(connect).unwrap();
}
I do not understand this error message because I am already importing futures.