pub async fn route_protocol(
    use_decl: UseProtocolDecl,
    target: &Arc<ComponentInstance>,
) -> Result<CapabilitySource, ModelError> {
    let allowed_sources = AllowedSourcesBuilder::new()
        .framework(InternalCapability::Protocol)
        .builtin(InternalCapability::Protocol)
        .namespace()
        .component()
        .capability();
    if let UseSource::Debug = use_decl.source {
        // Find the component instance in which the debug capability was registered with the environment.
        let (env_component_instance, env_name, registration_decl) =
            match target.environment().get_debug_capability(&use_decl.source_name)? {
                Some((ExtendedInstance::Component(env_component_instance), env_name, reg)) => {
                    (env_component_instance, env_name, reg)
                }
                Some((ExtendedInstance::AboveRoot(_), _, _)) => {
                    // Root environment.
                    return Err(RoutingError::UseFromRootEnvironmentNotAllowed {
                        moniker: target.abs_moniker.clone(),
                        capability_name: use_decl.source_name.clone(),
                        capability_type: DebugRegistration::TYPE,
                    }
                    .into());
                }
                None => {
                    return Err(RoutingError::UseFromEnvironmentNotFound {
                        moniker: target.abs_moniker.clone(),
                        capability_name: use_decl.source_name.clone(),
                        capability_type: DebugRegistration::TYPE,
                    }
                    .into());
                }
            };
        let env_name = env_name.expect(&format!(
            "Environment name in component `{}` not found when routing `{}`.",
            target.abs_moniker, use_decl.source_name
        ));

        let env_moniker = env_component_instance.abs_moniker.clone();

        let source = RoutingStrategy::new()
            .registration::<DebugRegistration>()
            .offer::<OfferProtocolDecl>()
            .expose::<ExposeProtocolDecl>()
            .route(
                registration_decl,
                env_component_instance.clone(),
                allowed_sources,
                &mut ProtocolVisitor,
            )
            .await?;

        target.try_get_context()?.policy().can_route_debug_capability(
            &source,
            &env_moniker,
            &env_name,
            &target.abs_moniker,
        )?;
        return Ok(source);
    } else {
        Ok(RoutingStrategy::new()
            .use_::<UseProtocolDecl>()
            .offer::<OfferProtocolDecl>()
            .expose::<ExposeProtocolDecl>()
            .route(use_decl, target.clone(), allowed_sources, &mut ProtocolVisitor)
            .await?)
    }
}
/// Routes a Protocol capability from `target` to its source, starting from `use_decl`.
Routes a Protocol capability from `target` to its source, starting from `use_decl`.
Routes a Protocol capability from ` target ` to its source starting from ` use_decl ` .
pub async fn route_protocol(
    use_decl: UseProtocolDecl,
    target: &Arc<ComponentInstance>,
) -> Result<CapabilitySource, ModelError> {
    let allowed_sources = AllowedSourcesBuilder::new()
        .framework(InternalCapability::Protocol)
        .builtin(InternalCapability::Protocol)
        .namespace()
        .component()
        .capability();
    if let UseSource::Debug = use_decl.source {
        // Find the component instance in which the debug capability was registered with the environment.
        let (env_component_instance, env_name, registration_decl) =
            match target.environment().get_debug_capability(&use_decl.source_name)? {
                Some((ExtendedInstance::Component(env_component_instance), env_name, reg)) => {
                    (env_component_instance, env_name, reg)
                }
                Some((ExtendedInstance::AboveRoot(_), _, _)) => {
                    // Root environment.
                    return Err(RoutingError::UseFromRootEnvironmentNotAllowed {
                        moniker: target.abs_moniker.clone(),
                        capability_name: use_decl.source_name.clone(),
                        capability_type: DebugRegistration::TYPE,
                    }
                    .into());
                }
                None => {
                    return Err(RoutingError::UseFromEnvironmentNotFound {
                        moniker: target.abs_moniker.clone(),
                        capability_name: use_decl.source_name.clone(),
                        capability_type: DebugRegistration::TYPE,
                    }
                    .into());
                }
            };
        let env_name = env_name.expect(&format!(
            "Environment name in component `{}` not found when routing `{}`.",
            target.abs_moniker, use_decl.source_name
        ));
        let env_moniker = env_component_instance.abs_moniker.clone();
        let source = RoutingStrategy::new()
            .registration::<DebugRegistration>()
            .offer::<OfferProtocolDecl>()
            .expose::<ExposeProtocolDecl>()
            .route(
                registration_decl,
                env_component_instance.clone(),
                allowed_sources,
                &mut ProtocolVisitor,
            )
            .await?;
        target.try_get_context()?.policy().can_route_debug_capability(
            &source,
            &env_moniker,
            &env_name,
            &target.abs_moniker,
        )?;
        return Ok(source);
    } else {
        Ok(RoutingStrategy::new()
            .use_::<UseProtocolDecl>()
            .offer::<OfferProtocolDecl>()
            .expose::<ExposeProtocolDecl>()
            .route(use_decl, target.clone(), allowed_sources, &mut ProtocolVisitor)
            .await?)
    }
}
pub async fn route_protocol ( use_decl : UseProtocolDecl , target : & Arc < ComponentInstance > , ) -> Result < CapabilitySource , ModelError > { let allowed_sources = AllowedSourcesBuilder :: new ( ) . framework ( InternalCapability :: Protocol ) . builtin ( InternalCapability :: Protocol ) . namespace ( ) . component ( ) . capability ( ) ; if let UseSource :: Debug = use_decl . source { // Find the component instance in which the debug capability was registered with the environment. let ( env_component_instance , env_name , registration_decl ) = match target . environment ( ) . get_debug_capability ( & use_decl . source_name ) ? { Some ( ( ExtendedInstance :: Component ( env_component_instance ) , env_name , reg ) ) => { ( env_component_instance , env_name , reg ) } Some ( ( ExtendedInstance :: AboveRoot ( _ ) , _ , _ ) ) => { // Root environment. return Err ( RoutingError :: UseFromRootEnvironmentNotAllowed { moniker : target . abs_moniker . clone ( ) , capability_name : use_decl . source_name . clone ( ) , capability_type : DebugRegistration :: TYPE , } . into ( ) ) ; } None => { return Err ( RoutingError :: UseFromEnvironmentNotFound { moniker : target . abs_moniker . clone ( ) , capability_name : use_decl . source_name . clone ( ) , capability_type : DebugRegistration :: TYPE , } . into ( ) ) ; } } ; let env_name = env_name . expect ( & format ! ( " " target abs_moniker use_decl source_name ) ) ; let env_moniker = env_component_instance . abs_moniker . clone ( ) ; let source = RoutingStrategy :: new ( ) . registration :: < DebugRegistration > ( ) . offer :: < OfferProtocolDecl > ( ) . expose :: < ExposeProtocolDecl > ( ) . route ( registration_decl , env_component_instance . clone ( ) , allowed_sources , & mut ProtocolVisitor , ) . await ? ; target . try_get_context ( ) ? . policy ( ) . can_route_debug_capability ( & source , & env_moniker , & env_name , & target . abs_moniker , ) ? ; return Ok ( source ) ; } else { Ok ( RoutingStrategy :: new ( ) . use_ :: < UseProtocolDecl > ( ) . offer :: < OfferProtocolDecl > ( ) . expose :: < ExposeProtocolDecl > ( ) . route ( use_decl , target . clone ( ) , allowed_sources , & mut ProtocolVisitor ) . await ? ) } }
Routes a Protocol capability from `target` to its source, starting from `use_decl`.
Routes a Protocol capability from ` target ` to its source starting from ` use_decl ` .
use_decl
UseProtocolDecl
target
&Arc<ComponentInstance>
use_decl
UseProtocolDecl
target
&Arc<ComponentInstance>