• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Bazel Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 extern crate grpc;
16 extern crate helloworld_proto;
17 
18 use grpc::ClientStubExt;
19 use std::env;
20 use std::str::FromStr;
21 
22 use helloworld_proto::*;
23 
parse_args() -> (String, u16)24 fn parse_args() -> (String, u16) {
25     let mut name = "world".to_owned();
26     let mut port = 50051;
27     for arg in env::args().skip(1) {
28         if let Some(argp) = arg.strip_prefix("-p=") {
29             port = u16::from_str(argp).unwrap()
30         } else {
31             name = arg.to_owned();
32         }
33     }
34     (name, port)
35 }
36 
main()37 fn main() {
38     let (name, port) = parse_args();
39     let client = GreeterClient::new_plain("::1", port, Default::default()).unwrap();
40     let mut req = HelloRequest::new();
41     req.set_name(name);
42     let resp = client.say_hello(grpc::RequestOptions::new(), req);
43     println!("{:?}", resp.wait());
44 }
45