What is the data type of tx in tokio_tungstenite::WebSocketStream?

What is the data type of tx in tokio_tungstenite::WebSocketStream?

I am trying to store in for later.

Split the tx & rx from websocket. tx variable will be stored in server type.
let (tx, rx) = stream.split();

server.rs

use axum::extract::ws::{Message, WebSocket};
use futures::stream::SplitSink;
use std::sync::Arc;
use tokio::sync::Mutex;
use tokio_tungstenite::WebSocketStream;

pub type Server = Arc<Mutex<SplitSink<WebSocketStream<_>, _>>>;

Error:

the placeholder `_` is not allowed within types on item signatures for type aliases
not allowed in type signatures

The generic parameter of WebSocketStream is the underlying stream you use to make the websocket connection. I assume it is tokio::net::TcpStream? The second generic parameter of the SplitSink is the Item parameter of WebSocketStreams Sink implementation, so tungstenite::protocol::Message.

@jofas Hi
I changed according to you but still getting the placeholder error.

use axum::extract::ws::{Message, WebSocket};
use futures::stream::SplitSink;
use std::sync::Arc;
use tokio::io::AsyncWriteExt;
use tokio::sync::Mutex;
use tokio_tungstenite::WebSocketStream;

pub type Server = Arc<Mutex<SplitSink<WebSocketStream<_>, Message>>>;

Yes, WebSocketStream<_> still has a placeholder. You need to put in the type from which you create the WebSocketStream. Is it tokio::net::TcpStream? Then your type would be WebSocketStream<tokio::net::TcpStream>. If it is a different type than tokio's TCP stream, you'd need to use that instead.

1 Like

@jofas Thanks a lot
This is working now.

use axum::extract::ws::Message;
use futures::stream::SplitSink;
use std::sync::Arc;
use tokio::net::TcpStream;
use tokio::sync::Mutex;
use tokio_tungstenite::WebSocketStream;

pub type Server = Arc<Mutex<SplitSink<WebSocketStream<TcpStream>, Message>>>;
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.