-1

I have a gRPC server and need to make a HTTP GET. I'm struggling getting the futures right in the calls.

I'm trying this

fn current(
    &self,
    _: ::grpc::RequestOptions,
    p: quote::CurrentRequest,
) -> ::grpc::SingleResponse<quote::CurrentResponse> {
    let symbol = p.get_symbol();

    let client = Client::new();
    let fut: grpc::GrpcFuture<quote::CurrentResponse> = Box::new(
        client
            .get(Uri::from_static(AlphaFunction::base_url()))
            .and_then(|res| res.into_body().concat2())
            .and_then(|body| {
                info!("body {:?}", body);
                let mut r = quote::CurrentResponse::new();
                // TODO: Parse body
                r.set_symbol(symbol.to_string());
                Ok(r)
            })
            .map_err(|e| e),
    );

    grpc::SingleResponse::new(fut)
}

But I get a bunch of errors:

expected struct `hyper::error::Error`, found enum `grpc::error::Error`

and

    77 |         grpc::SingleResponse::new(fut)
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `protos::quote::CurrentResponse`, found tuple
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Fredrik Jansson
  • 3,764
  • 3
  • 30
  • 33
  • 1
    It's hard to answer your question because it doesn't include a [MCVE]. We can't tell what crates (and their versions), types, traits, fields, etc. are present in the code. It would make it easier for us to help you if you try to reproduce your error on the [Rust Playground](https://play.rust-lang.org) if possible, otherwise in a brand new Cargo project, then [edit] your question to include the additional info. There are [Rust-specific MCVE tips](//stackoverflow.com/tags/rust/info) you can use to reduce your original code for posting here. Thanks! – Shepmaster Jun 12 '19 at 00:07
  • Lesson learned, thank you! – Fredrik Jansson Jun 12 '19 at 04:29

1 Answers1

0

I figured it out:

let fut = client
    .get(Uri::from_static(AlphaFunction::base_url()))
    .and_then(|res| res.into_body().concat2())
    .and_then(move |body| {
        info!("body {:?}", body);
        let mut r = quote::CurrentResponse::new();
        r.set_symbol(symbol.to_string());
        Ok(r)
    })
    .map_err(|e| grpc::Error::Panic(format!("{}", e)));
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Fredrik Jansson
  • 3,764
  • 3
  • 30
  • 33
  • Answers without any prose to describe what the changes were and why they were needed are only minimally helpful to those who attempt to use them afterward. – Shepmaster Jun 12 '19 at 17:34