| // Copyright 2018 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #![feature(async_await)] |
| |
| use argh::FromArgs; |
| use failure::{Error, ResultExt}; |
| use fidl_fidl_examples_echo::EchoMarker; |
| use fuchsia_async as fasync; |
| use fuchsia_component::client::{launcher, launch}; |
| |
| #[fasync::run_singlethreaded] |
| async fn main() -> Result<(), Error> { |
| #[allow(dead_code)] // FIXME(cramertj) this shouldn't be required |
| #[derive(FromArgs, Debug)] |
| /// Rust echo client |
| struct Opt { |
| /// URL of the echo server to run. |
| #[argh( |
| option, |
| long = "server", |
| default = "\"fuchsia-pkg://fuchsia.com/echo_server_rust#meta/echo_server_rust.cmx\"\ |
| .to_string()", |
| )] |
| server_url: String, |
| } |
| |
| // Launch the server and connect to the echo service. |
| let Opt { server_url } = argh::from_env(); |
| |
| let launcher = launcher().context("Failed to open launcher service")?; |
| let app = launch(&launcher, server_url, None) |
| .context("Failed to launch echo service")?; |
| |
| let echo = app.connect_to_service::<EchoMarker>() |
| .context("Failed to connect to echo service")?; |
| |
| let res = echo.echo_string(Some("hello world!")).await?; |
| println!("response: {:?}", res); |
| Ok(()) |
| } |