pub async fn new_named_instance(
        &self,
        child_name: impl Into<String>,
        url: impl Into<String>,
    ) -> Result<ScopedInstance, anyhow::Error> {
        let realm = if let Some(realm_proxy) = self.realm_proxy.as_ref() {
            realm_proxy.clone()
        } else {
            fclient::realm().context("Failed to connect to Realm service")?
        };
        let child_name = child_name.into();
        let mut collection_ref = fsys::CollectionRef { name: self.collection_name.clone() };
        let child_decl = fsys::ChildDecl {
            name: Some(child_name.clone()),
            url: Some(url.into()),
            startup: Some(fsys::StartupMode::Lazy),
            ..fsys::ChildDecl::EMPTY
        };
        let () = realm
            .create_child(&mut collection_ref, child_decl)
            .await
            .context("CreateChild FIDL failed.")?
            .map_err(|e| format_err!("Failed to create child: {:?}", e))?;
        let mut child_ref = fsys::ChildRef {
            name: child_name.clone(),
            collection: Some(self.collection_name.clone()),
        };
        let (exposed_dir, server) = endpoints::create_proxy::<fidl_fuchsia_io::DirectoryMarker>()
            .context("Failed to create directory proxy")?;
        let () = realm
            .bind_child(&mut child_ref, server)
            .await
            .context("BindChild FIDL failed.")?
            .map_err(|e| format_err!("Failed to bind to child: {:?}", e))?;
        Ok(ScopedInstance {
            realm,
            child_name,
            collection: self.collection_name.clone(),
            exposed_dir,
            destroy_channel: None,
        })
    }
/// Creates and binds to a new component named `child_name` with `url`.
/// A ScopedInstance is returned on success, representing the component's lifetime and
/// providing access to the component's exposed capabilities.
///
/// When the ScopedInstance is dropped, the component will be asynchronously stopped _and_
/// destroyed.
///
/// This is useful for tests that wish to create components that should be torn down at the
/// end of the test, or to explicitly control the lifecycle of a component.
Creates and binds to a new component named `child_name` with `url`.
A ScopedInstance is returned on success, representing the component's lifetime and
providing access to the component's exposed capabilities.

When the ScopedInstance is dropped, the component will be asynchronously stopped _and_
destroyed.

This is useful for tests that wish to create components that should be torn down at the
end of the test, or to explicitly control the lifecycle of a component.
Creates and binds to a new component named ` child_name ` with ` url ` . A ScopedInstance is returned on success representing the component ' s lifetime and providing access to the component ' s exposed capabilities . When the ScopedInstance is dropped the component will be asynchronously stopped _and_ destroyed . This is useful for tests that wish to create components that should be torn down at the end of the test or to explicitly control the lifecycle of a component .
pub async fn new_named_instance(
        &self,
        child_name: impl Into<String>,
        url: impl Into<String>,
    ) -> Result<ScopedInstance, anyhow::Error> {
        let realm = if let Some(realm_proxy) = self.realm_proxy.as_ref() {
            realm_proxy.clone()
        } else {
            fclient::realm().context("Failed to connect to Realm service")?
        };
        let child_name = child_name.into();
        let mut collection_ref = fsys::CollectionRef { name: self.collection_name.clone() };
        let child_decl = fsys::ChildDecl {
            name: Some(child_name.clone()),
            url: Some(url.into()),
            startup: Some(fsys::StartupMode::Lazy),
            ..fsys::ChildDecl::EMPTY
        };
        let () = realm
            .create_child(&mut collection_ref, child_decl)
            .await
            .context("CreateChild FIDL failed.")?
            .map_err(|e| format_err!("Failed to create child: {:?}", e))?;
        let mut child_ref = fsys::ChildRef {
            name: child_name.clone(),
            collection: Some(self.collection_name.clone()),
        };
        let (exposed_dir, server) = endpoints::create_proxy::<fidl_fuchsia_io::DirectoryMarker>()
            .context("Failed to create directory proxy")?;
        let () = realm
            .bind_child(&mut child_ref, server)
            .await
            .context("BindChild FIDL failed.")?
            .map_err(|e| format_err!("Failed to bind to child: {:?}", e))?;
        Ok(ScopedInstance {
            realm,
            child_name,
            collection: self.collection_name.clone(),
            exposed_dir,
            destroy_channel: None,
        })
    }
pub async fn new_named_instance ( & self , child_name : impl Into < String > , url : impl Into < String > , ) -> Result < ScopedInstance , anyhow :: Error > { let realm = if let Some ( realm_proxy ) = self . realm_proxy . as_ref ( ) { realm_proxy . clone ( ) } else { fclient :: realm ( ) . context ( " " ) ? } ; let child_name = child_name . into ( ) ; let mut collection_ref = fsys :: CollectionRef { name : self . collection_name . clone ( ) } ; let child_decl = fsys :: ChildDecl { name : Some ( child_name . clone ( ) ) , url : Some ( url . into ( ) ) , startup : Some ( fsys :: StartupMode :: Lazy ) , .. fsys :: ChildDecl :: EMPTY } ; let ( ) = realm . create_child ( & mut collection_ref , child_decl ) . await . context ( " " ) ? . map_err ( | e | format_err ! ( " " e ) ) ? ; let mut child_ref = fsys :: ChildRef { name : child_name . clone ( ) , collection : Some ( self . collection_name . clone ( ) ) , } ; let ( exposed_dir , server ) = endpoints :: create_proxy :: < fidl_fuchsia_io :: DirectoryMarker > ( ) . context ( " " ) ? ; let ( ) = realm . bind_child ( & mut child_ref , server ) . await . context ( " " ) ? . map_err ( | e | format_err ! ( " " e ) ) ? ; Ok ( ScopedInstance { realm , child_name , collection : self . collection_name . clone ( ) , exposed_dir , destroy_channel : None , } ) }
Creates and binds to a new component named `child_name` with `url`.
Creates and binds to a new component named ` child_name ` with ` url ` .
&self
child_name
impl Into<String>
url
impl Into<String>
&self
child_name
impl Into<String>
url
impl Into<String>