Hello,
I'm trying to understand the reasoning behind a requirement of stream forwarding which basically forces me to always "wrap" stream items with Ok.
Consider the following example:
let (ch1_tx, ch1_rx) = futures_channel::mpsc::channel::<String>(16);
let (ch2_tx, ch2_rx) = futures_channel::mpsc::channel::<String>(16);
let f = ch1_rx.map(Ok).forward(ch2_tx);
So if I don't write map(Ok)
above the code won't compile with an error:
error[E0271]: type mismatch resolving <futures_channel::mpsc::Receiver<std::string::String> as futures_core::stream::Stream>::Item == std::result::Result<_, _>
--> src/bin/my_test.rs:8:20
|
8 | let f = ch1_rx.forward(ch2_tx);
| ^^^^^^^ expected struct std::string::String
, found enum std::result::Result
|
= note: expected type std::string::String
found enum std::result::Result<_, _>
= note: required because of the requirements on the impl of futures_core::stream::TryStream
for futures_channel::mpsc::Receiver<std::string::String>
The question is why it was designed in such way that is it necessary to pass Result into the forwarding stream instead of just String? Also, when consuming items from ch2_rx
stream, they will come up as String
s not as Result
s, so I'm not sure why would forwarding an Err
be ever useful?
Thanks.