websockets-rs / rust-websocket

A WebSocket (RFC6455) library written in Rust
http://websockets-rs.github.io/rust-websocket/
MIT License
1.55k stars 223 forks source link

"the trait `futures::Future` is not implemented for `websocket::futures::AndThen<std::boxed......" #254

Closed xuanyimo closed 4 years ago

xuanyimo commented 4 years ago

I use code of https://github.com/websockets-rs/rust-websocket/blob/master/examples/async-client.rs

Cargo.toml

[dependencies]
futures = "0.3.5"
websocket = "0.26.0"
tokio = "0.2.22

screenshot:

image

error:

error[E0277]: `websocket::futures::AndThen<std::boxed::Box<dyn websocket::futures::Future<Item = (websocket::client::r#async::Framed<websocket::r#async::TcpStream, websocket::r#async::MessageCodec<websocket::OwnedMessage>>, websocket::header::Headers), Error = websocket::WebSocketError> + std::marker::Send>, websocket::futures::stream::Forward<websocket::futures::stream::Select<websocket::futures::stream::FilterMap<websocket::futures::stream::SplitStream<websocket::client::r#async::Framed<websocket::r#async::TcpStream, websocket::r#async::MessageCodec<websocket::OwnedMessage>>>, [closure@src/main.rs:63:29: 70:18]>, websocket::futures::stream::MapErr<websocket::futures::sync::mpsc::Receiver<websocket::OwnedMessage>, [closure@src/main.rs:72:42: 72:77]>>, websocket::futures::stream::SplitSink<websocket::client::r#async::Framed<websocket::r#async::TcpStream, websocket::r#async::MessageCodec<websocket::OwnedMessage>>>>, [closure@src/main.rs:59:19: 75:10 stdin_ch:_]>` is not a future
  --> src/main.rs:77:22
   |
77 |     runtime.block_on(runner).unwrap();
   |                      ^^^^^^ `websocket::futures::AndThen<std::boxed::Box<dyn websocket::futures::Future<Item = (websocket::client::r#async::Framed<websocket::r#async::TcpStream, websocket::r#async::MessageCodec<websocket::OwnedMessage>>, websocket::header::Headers), Error = websocket::WebSocketError> + std::marker::Send>, websocket::futures::stream::Forward<websocket::futures::stream::Select<websocket::futures::stream::FilterMap<websocket::futures::stream::SplitStream<websocket::client::r#async::Framed<websocket::r#async::TcpStream, websocket::r#async::MessageCodec<websocket::OwnedMessage>>>, [closure@src/main.rs:63:29: 70:18]>, websocket::futures::stream::MapErr<websocket::futures::sync::mpsc::Receiver<websocket::OwnedMessage>, [closure@src/main.rs:72:42: 72:77]>>, websocket::futures::stream::SplitSink<websocket::client::r#async::Framed<websocket::r#async::TcpStream, websocket::r#async::MessageCodec<websocket::OwnedMessage>>>>, [closure@src/main.rs:59:19: 75:10 stdin_ch:_]>` is not a future
   |
   = help: the trait `futures::Future` is not implemented for `websocket::futures::AndThen<std::boxed::Box<dyn websocket::futures::Future<Item = (websocket::client::r#async::Framed<websocket::r#async::TcpStream, websocket::r#async::MessageCodec<websocket::OwnedMessage>>, websocket::header::Headers), Error = websocket::WebSocketError> + std::marker::Send>, websocket::futures::stream::Forward<websocket::futures::stream::Select<websocket::futures::stream::FilterMap<websocket::futures::stream::SplitStream<websocket::client::r#async::Framed<websocket::r#async::TcpStream, websocket::r#async::MessageCodec<websocket::OwnedMessage>>>, [closure@src/main.rs:63:29: 70:18]>, websocket::futures::stream::MapErr<websocket::futures::sync::mpsc::Receiver<websocket::OwnedMessage>, [closure@src/main.rs:72:42: 72:77]>>, websocket::futures::stream::SplitSink<websocket::client::r#async::Framed<websocket::r#async::TcpStream, websocket::r#async::MessageCodec<websocket::OwnedMessage>>>>, [closure@src/main.rs:59:19: 75:10 stdin_ch:_]>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `cock`.

To learn more, run the command again with --verbose.
vi commented 4 years ago

rust-websocket is in futures 0.1 / tokio 0.1, pre-async/await world for now.

You may want to use other websocket crate or use some adapters like https://github.com/tokio-rs/tokio-compat.