[fuchsia-ui] Use fuchsia-component

Testing: manual
Change-Id: Ia6a62209ccea58bb66831224ef1c73db90c541f4
diff --git a/public/rust/fuchsia-ui/BUILD.gn b/public/rust/fuchsia-ui/BUILD.gn
index cd75bbd..8258945 100644
--- a/public/rust/fuchsia-ui/BUILD.gn
+++ b/public/rust/fuchsia-ui/BUILD.gn
@@ -20,7 +20,7 @@
     "//garnet/public/fidl/fuchsia.ui.viewsv1token:fuchsia.ui.viewsv1token-rustc",
     "//garnet/public/lib/fidl/rust/fidl",
     "//garnet/public/rust/fdio",
-    "//garnet/public/rust/fuchsia-app",
+    "//garnet/public/rust/fuchsia-component",
     "//garnet/public/rust/fuchsia-async",
     "//garnet/public/rust/fuchsia-scenic",
     "//garnet/public/rust/fuchsia-zircon",
@@ -46,7 +46,7 @@
     "//garnet/public/fidl/fuchsia.ui.viewsv1token:fuchsia.ui.viewsv1token-rustc",
     "//garnet/public/lib/fidl/rust/fidl",
     "//garnet/public/rust/fdio",
-    "//garnet/public/rust/fuchsia-app",
+    "//garnet/public/rust/fuchsia-component",
     "//garnet/public/rust/fuchsia-async",
     "//garnet/public/rust/fuchsia-scenic",
     "//garnet/public/rust/fuchsia-ui",
diff --git a/public/rust/fuchsia-ui/src/app.rs b/public/rust/fuchsia-ui/src/app.rs
index 2d86fe4..9647ec8 100644
--- a/public/rust/fuchsia-ui/src/app.rs
+++ b/public/rust/fuchsia-ui/src/app.rs
@@ -11,10 +11,11 @@
     ViewProviderRequestStream,
 };
 use fidl_fuchsia_ui_viewsv1token::ViewOwnerMarker;
-use fuchsia_app::{self as component, client::connect_to_service, server::FdioServer};
 use fuchsia_async as fasync;
+use fuchsia_component::{client::connect_to_service, server::take_service_connect_stream};
 use fuchsia_scenic::SessionPtr;
 use fuchsia_zircon::EventPair;
+use futures::prelude::*;
 use futures::{TryFutureExt, TryStreamExt};
 use lazy_static::lazy_static;
 use parking_lot::Mutex;
@@ -87,12 +88,10 @@
 
         APP.lock().set_assistant(Mutex::new(assistant));
 
-        let fut = Self::start_services(&APP)?;
+        Self::start_services(&APP, &mut executor)?;
 
         APP.lock().assistant.as_ref().unwrap().lock().setup()?;
 
-        executor.run_singlethreaded(fut)?;
-
         Ok(())
     }
 
@@ -170,17 +169,23 @@
         )
     }
 
-    fn start_services(app: &AppPtr) -> Result<FdioServer, Error> {
-        let app_view_provider = app.clone();
-        let app_view_provider2 = app.clone();
-        let services_server = component::server::ServicesServer::new();
-        let services_server = services_server
-            .add_service((ViewProviderMarker::NAME, move |channel| {
-                Self::spawn_view_provider_server(channel, &app_view_provider);
-            }))
-            .add_service((viewsv2::ViewProviderMarker::NAME, move |channel| {
-                Self::spawn_v2_view_provider_server(channel, &app_view_provider2);
-            }));
-        Ok(services_server.start()?)
+    fn start_services(app: &AppPtr, executor: &mut fasync::Executor) -> Result<(), Error> {
+        let fut = take_service_connect_stream()?.for_each_concurrent(
+            None,
+            async move |(name, channel)| {
+                if name == ViewProviderMarker::NAME {
+                    let async_chan =
+                        fasync::Channel::from_channel(channel).expect("failed to convert channel");
+                    Self::spawn_view_provider_server(async_chan, &app.clone());
+                } else if name == viewsv2::ViewProviderMarker::NAME {
+                    let async_chan =
+                        fasync::Channel::from_channel(channel).expect("failed to convert channel");
+                    Self::spawn_v2_view_provider_server(async_chan, &app.clone());
+                }
+            },
+        );
+        executor.run_singlethreaded(fut);
+
+        Ok(())
     }
 }
diff --git a/public/rust/fuchsia-ui/src/lib.rs b/public/rust/fuchsia-ui/src/lib.rs
index 832ed07..de3813b 100644
--- a/public/rust/fuchsia-ui/src/lib.rs
+++ b/public/rust/fuchsia-ui/src/lib.rs
@@ -10,6 +10,7 @@
 //! [Rust](https://www.rust-lang.org/).
 
 #![deny(missing_docs)]
+#![feature(async_await)]
 
 mod app;
 mod canvas;