Calling for method "poll_next()" on a ClientSStreamReceiver gives error: "method not found"

Hi,

I have been struggling with an issue for a couple of hours now and I can't find any solution,
so now I'm reaching out to you for help. And yes, I am a beginner in Rust, so please have that in mind.

I'm trying to call for the function poll_next() on a ClientSStreamReceiver, and according to the documentation
https://docs.rs/grpcio/0.6.0/grpcio/struct.ClientSStreamReceiver.html it should be a method with that name. And if I click into the ClientSStreamReceiver, the method is implemented as well, as I understand it.

impl<Resp> Stream for ClientSStreamReceiver<Resp> {
    type Item = Result<Resp>;

    #[inline]
    fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
        Pin::new(&mut self.imp).poll(cx)
    }
}

Maybe I use the function wrong in my application, it seems like the function wants a context-parameter, but I don't know how to pass it in.

  let sub_info = client.subscribe_to_signals(&subscriber_config).unwrap();
  match sub_info.pull_next() {}

And here is my error code is:

46 |     match sub_info.poll_next() {}
   |                    ^^^^^^^^^ method not found in `protos::grpcio::ClientSStreamReceiver<protos::network_api::Signals>`

My code is on GitHub as well, if you want to take a closer look: https://github.com/niclaslind/signalbroker-record-replay

Thanks in advance

// Niclas

Please look into async_book.
Your function should be async and then you should be able to do something like

match sub_info.next().await {
    Ok(Resp) => ...,
    Err(e) => ...
}
1 Like

Please don't post Rust code in images. Please follow the Forum Code Formatting and Syntax Highlighting guidelines that are pinned to the top of this forum so that all new posters will see them.

1 Like

Hej Tom,

I will definitely read the post, I have removed the images now.

/ Niclas

The poll method is defined on a pinned stream, not on a bare stream.

Thanks!

I needed to change the return as well.
Because it was expecting enum std::option::Option, and not enum std::result::Result

So instead of

Ok(Resp) => ...,
Err(e) => ...

it should be

Some(n) => ...,
None => ...,

// Niclas

No problem. Glad it worked.