()
| 36 | } |
| 37 | |
| 38 | fn run() -> thrift::Result<()> { |
| 39 | let options = clap_app!(rust_tutorial_client => |
| 40 | (version: "0.1.0") |
| 41 | (author: "Apache Thrift Developers <dev@thrift.apache.org>") |
| 42 | (about: "Thrift Rust tutorial client") |
| 43 | (@arg host: --host +takes_value "host on which the tutorial server listens") |
| 44 | (@arg port: --port +takes_value "port on which the tutorial server listens") |
| 45 | ); |
| 46 | let matches = options.get_matches(); |
| 47 | |
| 48 | // get any passed-in args or the defaults |
| 49 | let host = matches.value_of("host").unwrap_or("127.0.0.1"); |
| 50 | let port = value_t!(matches, "port", u16).unwrap_or(9090); |
| 51 | |
| 52 | // build our client and connect to the host:port |
| 53 | let mut client = new_client(host, port)?; |
| 54 | |
| 55 | // alright! |
| 56 | // let's start making some calls |
| 57 | |
| 58 | // let's start with a ping; the server should respond |
| 59 | println!("ping!"); |
| 60 | client.ping()?; |
| 61 | |
| 62 | // simple add |
| 63 | println!("add"); |
| 64 | let res = client.add(1, 2)?; |
| 65 | println!("added 1, 2 and got {}", res); |
| 66 | |
| 67 | let logid = 32; |
| 68 | |
| 69 | // let's do...a multiply! |
| 70 | let res = client.calculate(logid, Work::new(7, 8, Operation::MULTIPLY, None))?; |
| 71 | println!("multiplied 7 and 8 and got {}", res); |
| 72 | |
| 73 | // let's get the log for it |
| 74 | let res = client.get_struct(logid /* 32 */)?; |
| 75 | println!("got log {:?} for operation {}", res, logid); |
| 76 | |
| 77 | // ok - let's be bad :( |
| 78 | // do a divide by 0 |
| 79 | // logid doesn't matter; won't be recorded |
| 80 | let res = client.calculate(77, Work::new(2, 0, Operation::DIVIDE, "we bad".to_owned())); |
| 81 | |
| 82 | // we should have gotten an exception back |
| 83 | match res { |
| 84 | Ok(v) => panic!("should not have succeeded with result {}", v), |
| 85 | Err(e) => println!("divide by zero failed with error {:?}", e), |
| 86 | } |
| 87 | |
| 88 | // let's do a one-way call |
| 89 | println!("zip"); |
| 90 | client.zip()?; |
| 91 | |
| 92 | // and then close out with a final ping |
| 93 | println!("ping!"); |
| 94 | client.ping()?; |
| 95 |
no test coverage detected