Q:

StreamExt::forward fails with error `expected integer, found enum `std::result::Result``

I'm trying to connect a rust futures stream (repeat) to a sink (drain).
The first method works fine (check below), but the second one with .forward fails to compile (the error is shown inline). Any pointers on what I'm doing wrong?
use futures::stream::StreamExt;
use futures::sink::SinkExt;
use futures::executor;

fn main() {
    executor::block_on( async {
        // works
        let mut work = futures::stream::repeat(5);
        let mut drain = futures::sink::drain();
        match drain.send(work.next()).await {
            Ok(_r) => println!("Done"),
            Err(_e) => println!("Error"),
        };

        // works
        let res: Vec<i32> = futures::stream::repeat(5).take(3).collect::<Vec<i32>>().await;
        println!("{:?}", res);

        // doesn't work
        // futures::stream::repeat(5).forward(futures::sink::drain());
        //                            ^^^^^^^ expected integer, found enum `std::result::Result`
        //  error[E0271]: type mismatch resolving `<futures_util::stream::repeat::Repeat<{integer}> as futures_core::stream::Stream>::Item == std::result::Result<_, _>`

        // Fixed above with repeat(Ok(5)) but not repeat(5)
        match futures::stream::repeat(Ok(5)).take(3).forward(futures::sink::drain()).await {
            Ok(_r) => println!("Done"),
            Err(_e) => println!("Error"),
        };
    });
}

Relevant docs

https://docs.rs/futures/0.3.1/futures/stream/fn.repeat.html
https://docs.rs/futures/0.3.1/futures/sink/fn.drain.html
https://docs.rs/futures/0.3.1/futures/stream/trait.StreamExt.html#method.forward

A:

I guess you wanted something a bit more like this?
use futures::stream::StreamExt;
use futures::sink::SinkExt;

#[tokio::main]
async fn main() {
    // works
    let mut work = futures::stream::repeat(5);
    let mut drain = futures::sink::drain();
    match drain.send(work.next()).await {
        Ok(_r) => println!("Done"),
        Err(_e) => println!("Error"),
    };
    // doesn't work

    futures::stream::repeat(Ok(5)).forward(futures::sink::drain());
}

As the error (slightly confusingly) illustrates, the repeat call must take a Result argument in this case.

