Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

error[E0628]: generators cannot have explicit arguments #61

Open
realcr opened this issue Feb 7, 2018 · 3 comments
Open

error[E0628]: generators cannot have explicit arguments #61

realcr opened this issue Feb 7, 2018 · 3 comments

Comments

@realcr
Copy link

realcr commented Feb 7, 2018

Hi, I am trying to write a function that takes a stream and splits it into a few sinks.
It's my first code with futures-await so I might be doing something strange here.
This is what my function looks like:

#[async]
fn stream_split<S,T,E>(stream: S, sinks: Vec<mpsc::Sender<T>>) -> Result<(),()> 
where
    S: Stream<Item=T, Error=E>,
    T: Clone,
{
    let mut sinks = sinks;

    #[async]
    for item in stream {
        sinks = sinks.into_iter().filter_map(|sink| {
            match await!(sink.send(item.clone())) {
                Ok(sink) => Some(sink),
                Err(_) => None,
            }
        });
    }
}

When trying to compile, I get this error message:

error[E0628]: generators cannot have explicit arguments
   --> src/frag_msg_receiver.rs:111:50
    |
111 |             sinks = sinks.into_iter().filter_map(|sink| {
    |                                                  ^^^^^^

error: aborting due to previous error

What is the meaning of this error message? What can I do to make my code compile?

The version of my compiler:

$ rustc --version
rustc 1.25.0-nightly (8ccab7eed 2018-01-31)

I have futures-await = "0.1.0" in my Cargo.toml.

Thank you for your extraordinary work on futures-await!

@alexcrichton
Copy link
Owner

Ah it looks like this is a bad error message! The problem here is that await! is in a closure when it only works inside an #[async] function or an async! block

@realcr
Copy link
Author

realcr commented Feb 7, 2018

I see. @alexcrichton: What is the reasonable way to make the code from above work?
Can I put #[async] somehow above the closure, or do I have to turn it into a separate function?
Thank you for your help!

@alexcrichton
Copy link
Owner

Inside the closure you may want to do --

.filter_map(|sink| {
    async_block! {
        // code using `await!`
    }
})

perhaps?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants