najamelan / ws_stream_tungstenite

Provide AsyncRead/AsyncWrite over tungstenite websockets
32 stars 16 forks source link

WsStream::new( ) mismatched types with async-tungstenite 0.24 #16

Closed qgerman2 closed 9 months ago

qgerman2 commented 9 months ago

with async-tungstenite 0.24 as a dependency, the following code fails

use async_tungstenite::accept_async;
use async_tungstenite::tokio::TokioAdapter;
use log::*;
use std::{io, net::SocketAddr, str::FromStr};
use tokio::net::{TcpListener, TcpStream};
use ws_stream_tungstenite::*;

#[tokio::main]
async fn main() {
    let addr = SocketAddr::from_str("127.0.0.1").unwrap();
    let socket = TcpListener::bind(&addr).await.unwrap();
    loop {
        tokio::spawn(connection(socket.accept().await));
    }
}

async fn connection(stream: Result<(TcpStream, SocketAddr), io::Error>) {
    let Ok((stream, addr)) = stream else { return };
    let Ok(stream) = accept_async(TokioAdapter::new(stream)).await else {
        return;
    };
    info!("CONECTADO {}", addr);
    let stream = WsStream::new(stream);
}

with error

error[E0308]: mismatched types
   --> src\main.rs:23:32
    |
23  |     let stream = WsStream::new(stream);
    |                  ------------- ^^^^^^ expected `WebSocketStream<_>`, found `WebSocketStream<TokioAdapter<TcpStream>>`
    |                  |
    |                  arguments to this function are incorrect

with Cargo.toml dependencies as

[dependencies]
futures = "^0.3"
log = "0.4.20"
tokio = {version="1.36.0", features=["full"]}
ws_stream_tungstenite = "0.11.0"
async-tungstenite = {version="0.24", features=["tokio-runtime"]}

however, if async-tungstenite version is set to 0.23 it compiles fine

najamelan commented 9 months ago

Version ws_stream_tungstenite 0.12 has been released that updates to the latest version of tungstenite and async-tungstenite.

swanandx commented 9 months ago

Hey @najamelan , looks like async-tungstenite released 0.25 last week as well! which causes the same issue again: image

can you please update it again? thanks!

ps: for future, would it be better if we don't pin the version with ^?

najamelan commented 9 months ago

I will do another update. Unfortunately these are breaking changes. Until (async)-tungstenite stabilize their API, unfortunately there is nothing we can do downstream but to update all the time. Cargo won't update minor versions until they release 1.x.

najamelan commented 9 months ago

0.13.0 was published to crates.

swanandx commented 9 months ago

Thank you so much! 🚀