message-io icon indicating copy to clipboard operation
message-io copied to clipboard

Mismatched types error when compiling with websocket feature

Open h2cone opened this issue 10 months ago • 4 comments

First of all, thank you for maintaining such a great project! While testing the WebSocket functionality with the example code provided in the All in one: TCP, UDP and WebSocket echo server, I encountered a compilation error when enabling the websocket feature (or using default features).

The following compilation errors occur:

❯ cargo run
   Compiling message-io v0.18.2
error[E0308]: mismatched types
   --> /home/metaflow/.cargo/registry/src/index.crates.io-6f17d22bba15001f/message-io-0.18.2/src/adapters/ws.rs:138:42
    |
138 | ...                   process_data(&data);
    |                       ------------ ^^^^^ expected `&[u8]`, found `&Payload`
    |                       |
    |                       arguments to this function are incorrect
    |
    = note: expected reference `&[u8]`
               found reference `&Payload`
note: type parameter defined here
   --> /home/metaflow/.cargo/registry/src/index.crates.io-6f17d22bba15001f/message-io-0.18.2/src/adapters/ws.rs:116:41
    |
116 |     fn receive(&self, mut process_data: impl FnMut(&[u8])) -> ReadStatus {
    |                                         ^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> /home/metaflow/.cargo/registry/src/index.crates.io-6f17d22bba15001f/message-io-0.18.2/src/adapters/ws.rs:165:47
    |
165 |                 let message = Message::Binary(data.to_vec());
    |                               --------------- ^^^^^^^^^^^^^ expected `Payload`, found `Vec<u8>`
    |                               |
    |                               arguments to this enum variant are incorrect
    |
    = note: expected enum `Payload`
             found struct `std::vec::Vec<u8>`
note: tuple variant defined here
   --> /home/metaflow/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tungstenite-0.25.0/src/protocol/message.rs:159:5
    |
159 |     Binary(Payload),
    |     ^^^^^^
help: try wrapping the expression in `tungstenite::protocol::frame::Payload::Vec`
    |
165 |                 let message = Message::Binary(tungstenite::protocol::frame::Payload::Vec(data.to_vec()));
    |                                               +++++++++++++++++++++++++++++++++++++++++++             +

For more information about this error, try `rustc --explain E0308`.
error: could not compile `message-io` (lib) due to 2 previous errors

h2cone avatar Dec 17 '24 14:12 h2cone