Why this param is trait object?

#1

Use traits_preview and move UnboundedReceiver, how come it becomes trait object whereas it is a struct?
https://docs.rs/futures-preview/0.3.0-alpha.12/futures/channel/mpsc/struct.UnboundedReceiver.html
https://docs.rs/futures-preview/0.3.0-alpha.12/futures/stream/trait.StreamExt.html#method.left_stream

use futures::channel::mpsc;
use futures::stream::{Stream, StreamExt};

fn test(event_in: mpsc::UnboundedReceiver<String>) {
    let event_in = event_in.left_stream::<Stream<Item=()>>();
}
fn main() {}
error: the `left_stream` method cannot be invoked on a trait object
 --> src/main.rs:5:29
  |
5 |     let event_in = event_in.left_stream::<Stream<Item=()>>();
  |                             ^^^^^^^^^^^
help: another candidate was found in the following trait, perhaps add a `use` for it:
  |
1 | use futures_util::stream::StreamExt;
  |

Dependencies:

[dependencies]
futures = {version = "0.3.0-alpha.12", package = "futures-preview"}
0 Likes

#2

Stream<Item=()> is the trait object it does not support. Also Item must match.

if type inference is not filling in the value (with right_stream) then you have to fill it with the type you want. Box can often do the job.

let event_in = event_in.left_stream::<Box<dyn Stream<Item=String>>>();
1 Like