Hi, I have an error with associated types that I do not understand:
My code looks roughly like this:
use bytes;
use std::io;
use futures::channel::mpsc;
use async_std::task;
pub fn my_rx() -> impl futures::TryStream<Ok=(bytes::Bytes, std::net::SocketAddr), Error=std::io::Error> {
unimplemented!()
}
fn main() {
let inet_rx = my_rx();
let (tx1, inet_rx1) = mpsc::unbounded();
let (tx2, inet_rx2) = mpsc::unbounded();
let mut tx = tx1.fanout(tx2).sink_map_err(|_| io::Error::new(io::ErrorKind::Other, "Send Error"));
let foo = inet_rx.forward(tx);
let _ = task::spawn(foo);
}
And the error message I'm getting is:
error[E0271]: type mismatch resolving `<impl futures_core::stream::TryStream as futures_core::stream::Stream>::Item == std::result::Result<(bytes::bytes::Bytes, std::net::SocketAddr), std::io::Error>`
--> src/main.rs:220:13
|
220 | let _ = task::spawn(foo);
| ^^^^^^^^^^^ expected associated type, found enum `std::result::Result`
|
= note: expected associated type `<impl futures_core::stream::TryStream as futures_core::stream::Stream>::Item`
found enum `std::result::Result<(bytes::bytes::Bytes, std::net::SocketAddr), std::io::Error>`
= note: consider constraining the associated type `<impl futures_core::stream::TryStream as futures_core::stream::Stream>::Item` to `std::result::Result<(bytes::bytes::Bytes, std::net::SocketAddr), std::io::Error>` or calling a method that returns `<impl futures_core::stream::TryStream as futures_core::stream::Stream>::Item`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
= note: required because of the requirements on the impl of `core::future::future::Future` for `futures_util::stream::stream::forward::Forward<impl futures_core::stream::TryStream, futures_util::sink::map_err::SinkMapErr<futures_util::sink::fanout::Fanout<futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>, futures_channel::mpsc::UnboundedSender<(bytes::bytes::Bytes, std::net::SocketAddr)>>, [closure@src/main.rs:218:47: 218:101]>>`
So rust tells me that <TryStream as Stream>::Item
is not eqal to Result<(Bytes, SocketAddr), io::Error>
.
I really do not understand what the issue is here, because Stream::Item
should be Result<TryStream::Ok, TryStream::Error>
and that should be equal to Result<(Bytes, SocketAddr), io::Error>
.
Can somebody tell me why the compiler is complaining?