Hello, new rust user here;;
Just wanted to ask if anyone can help me with them traits usage:
I have a splitstream and splitsink (got them from tokio WS library split)
The underlying type for sink is for example:
SplitStream<WebSocketStream<TlsStream<TcpStream>>>
I want to "store" this (move it) to a struct member
pub struct Whatever {
...
sink : SplitStream<WebSocketStream<TlsStream<TcpStream>>>,
...
}
If i move the splitsink to a structure member, and then try to use it inside a method i define:
impl Whatever {
async fn consume_msg(&self) {
let f = self.sink.next().await;
^^^^ method cannot be called due to unsatisfied trait bounds
I hit the usatisfied trait bounds err;
47 | pub struct SplitSink<S, Item> {
| -----------------------------
| |
| doesn't satisfy `_: StreamExt`
| doesn't satisfy `_: Stream`
|
= note: the following trait bounds were not satisfied:
`SplitSink<WebSocketStream<tokio_native_tls::TlsStream<tokio::net::TcpStream>>, tokio_tungstenite::tungstenite::Mess
age>: futures_util::Stream`
which is required by `SplitSink<WebSocketStream<tokio_native_tls::TlsStream<tokio::net::TcpStream>>, tokio_tungstenite::tungstenite::Message>:StreamExt`
However, the following snippet works fine...
(i want to implement a method of struct Whatever that would resolve-in the next element in WebSocketStream)
let (outgoing, mut incoming) = ws_stream.split();
let msg = incoming.next().await;
I'm not really sure it's the place to ask, but can anyone please hlep me understand the trait bounding concept? I mean, why do i even bother with trait bounds, if i'm encapsulating the underlying instance of SplitSink in my own structure, why my structure or method has to implement the StreamExt traits?