Store value in variable (grpc)


#1

I want to store code value in variable instead of printing it,

let resp = client.generate_hash(grpc::RequestOptions::new(), req);
match resp.wait() {
Err(e) => panic!("{:?}", e),
Ok((_, code, _)) => println!("{:?}",code),

};

the code value is returned to the client node from the server node


#2

match can be an expression, so this would be most ideomatic:

let resp = client.generate_has(grpc::RequestOptions::new(), req);
let code = match resp.wait() {
               Err(e) => panic!("{:?}", e),
               Ok((_, code, _)) => code,
           };

#3

Thanks for the reply, it is working but instead of it storing just the code (e.g code = 7481050193809331123 ) it is now storing code = code: "7481050193809331123"


#4

Well, wait seems to return the type Result<(Metadata, T, Metadata)>, so code is going to be of type T. Without seeing more of your code here, and knowing what you’re trying to do, that seems correct.

If you’re just asking how to parse that string into an integer, try let code_as_int = code.parse::<usize>().expect("Could not parse code");