async fn route_storage_capability<'a>(
    model: &'a Model,
    use_decl: &'a UseStorageDecl,
    use_abs_moniker: AbsoluteMoniker,
) -> Result<(AbsoluteMoniker, CapabilityPath, RelativeMoniker), ModelError> {
    // Walk the offer chain to find the storage decl
    let parent_moniker = match use_abs_moniker.parent() {
        Some(m) => m,
        None => {
            return Err(ModelError::capability_discovery_error(format_err!(
                "storage capabilities cannot come from component manager's namespace"
            )))
        }
    };
    let mut pos = WalkPosition {
        capability: ComponentCapability::Use(UseDecl::Storage(use_decl.clone())),
        last_child_moniker: use_abs_moniker.path().last().map(|c| c.clone()),
        moniker: Some(parent_moniker),
    };

    let source = walk_offer_chain(model, &mut pos).await?;

    let (storage_decl, storage_decl_moniker) = match source {
        Some(CapabilitySource::StorageDecl(decl, moniker)) => (decl, moniker),
        _ => {
            return Err(ModelError::capability_discovery_error(format_err!(
                "storage capabilities must come from a storage declaration"
            )))
        }
    };
    let relative_moniker = RelativeMoniker::from_absolute(&storage_decl_moniker, &use_abs_moniker);

    // Find the path and source of the directory consumed by the storage capability.
    let (dir_source_path, dir_source_moniker) = match storage_decl.source {
        StorageDirectorySource::Self_ => (storage_decl.source_path, storage_decl_moniker),
        StorageDirectorySource::Realm => {
            let capability = ComponentCapability::Storage(storage_decl);
            let source = find_capability_source(model, capability, &storage_decl_moniker).await?;
            match source {
                CapabilitySource::Component { capability, source_moniker } => {
                    (capability.source_path().unwrap().clone(), source_moniker)
                }
                _ => {
                    return Err(ModelError::capability_discovery_error(format_err!(
                        "storage capability backing directories must be provided by a component"
                    )))
                }
            }
        }
        StorageDirectorySource::Child(ref name) => {
            let mut pos = {
                let partial = PartialMoniker::new(name.to_string(), None);
                let storage_decl_realm = model.look_up_realm(&storage_decl_moniker).await?;
                let realm_state = storage_decl_realm.lock_state().await;
                let realm_state =
                    realm_state.as_ref().expect("route_storage_capability: not resolved");
                let moniker =
                    Some(realm_state.extend_moniker_with(&storage_decl_moniker, &partial).ok_or(
                        ModelError::capability_discovery_error(format_err!(
                            "no child {} found from component {} for storage directory source",
                            partial,
                            pos.moniker().clone(),
                        )),
                    )?);
                let capability = ComponentCapability::Storage(storage_decl);
                WalkPosition { capability, last_child_moniker: None, moniker }
            };
            match walk_expose_chain(model, &mut pos).await? {
                CapabilitySource::Component { capability, source_moniker } => {
                    (capability.source_path().unwrap().clone(), source_moniker)
                }
                _ => {
                    return Err(ModelError::capability_discovery_error(format_err!(
                        "storage capability backing directories must be provided by a component"
                    )))
                }
            }
        }
    };
    Ok((dir_source_moniker, dir_source_path, relative_moniker))
}
/// Assuming `use_decl` is a UseStorage declaration, returns information about the source of the
/// storage capability, including:
/// - AbsoluteMoniker of the component hosting the backing directory capability
/// - Path to the backing directory capability
/// - Relative moniker between the backing directory component and the consumer, which identifies
///   the isolated storage directory.
Assuming `use_decl` is a UseStorage declaration, returns information about the source of the
storage capability, including:
AbsoluteMoniker of the component hosting the backing directory capability
Path to the backing directory capability
Relative moniker between the backing directory component and the consumer, which identifies
the isolated storage directory.
Assuming ` use_decl ` is a UseStorage declaration returns information about the source of the storage capability including : AbsoluteMoniker of the component hosting the backing directory capability Path to the backing directory capability Relative moniker between the backing directory component and the consumer which identifies the isolated storage directory .
async fn route_storage_capability<'a>(
    model: &'a Model,
    use_decl: &'a UseStorageDecl,
    use_abs_moniker: AbsoluteMoniker,
) -> Result<(AbsoluteMoniker, CapabilityPath, RelativeMoniker), ModelError> {
    // Walk the offer chain to find the storage decl
    let parent_moniker = match use_abs_moniker.parent() {
        Some(m) => m,
        None => {
            return Err(ModelError::capability_discovery_error(format_err!(
                "storage capabilities cannot come from component manager's namespace"
            )))
        }
    };
    let mut pos = WalkPosition {
        capability: ComponentCapability::Use(UseDecl::Storage(use_decl.clone())),
        last_child_moniker: use_abs_moniker.path().last().map(|c| c.clone()),
        moniker: Some(parent_moniker),
    };
    let source = walk_offer_chain(model, &mut pos).await?;
    let (storage_decl, storage_decl_moniker) = match source {
        Some(CapabilitySource::StorageDecl(decl, moniker)) => (decl, moniker),
        _ => {
            return Err(ModelError::capability_discovery_error(format_err!(
                "storage capabilities must come from a storage declaration"
            )))
        }
    };
    let relative_moniker = RelativeMoniker::from_absolute(&storage_decl_moniker, &use_abs_moniker);
    // Find the path and source of the directory consumed by the storage capability.
    let (dir_source_path, dir_source_moniker) = match storage_decl.source {
        StorageDirectorySource::Self_ => (storage_decl.source_path, storage_decl_moniker),
        StorageDirectorySource::Realm => {
            let capability = ComponentCapability::Storage(storage_decl);
            let source = find_capability_source(model, capability, &storage_decl_moniker).await?;
            match source {
                CapabilitySource::Component { capability, source_moniker } => {
                    (capability.source_path().unwrap().clone(), source_moniker)
                }
                _ => {
                    return Err(ModelError::capability_discovery_error(format_err!(
                        "storage capability backing directories must be provided by a component"
                    )))
                }
            }
        }
        StorageDirectorySource::Child(ref name) => {
            let mut pos = {
                let partial = PartialMoniker::new(name.to_string(), None);
                let storage_decl_realm = model.look_up_realm(&storage_decl_moniker).await?;
                let realm_state = storage_decl_realm.lock_state().await;
                let realm_state =
                    realm_state.as_ref().expect("route_storage_capability: not resolved");
                let moniker =
                    Some(realm_state.extend_moniker_with(&storage_decl_moniker, &partial).ok_or(
                        ModelError::capability_discovery_error(format_err!(
                            "no child {} found from component {} for storage directory source",
                            partial,
                            pos.moniker().clone(),
                        )),
                    )?);
                let capability = ComponentCapability::Storage(storage_decl);
                WalkPosition { capability, last_child_moniker: None, moniker }
            };
            match walk_expose_chain(model, &mut pos).await? {
                CapabilitySource::Component { capability, source_moniker } => {
                    (capability.source_path().unwrap().clone(), source_moniker)
                }
                _ => {
                    return Err(ModelError::capability_discovery_error(format_err!(
                        "storage capability backing directories must be provided by a component"
                    )))
                }
            }
        }
    };
    Ok((dir_source_moniker, dir_source_path, relative_moniker))
}
async fn route_storage_capability < ' a > ( model : & ' a Model , use_decl : & ' a UseStorageDecl , use_abs_moniker : AbsoluteMoniker , ) -> Result < ( AbsoluteMoniker , CapabilityPath , RelativeMoniker ) , ModelError > { // Walk the offer chain to find the storage decl let parent_moniker = match use_abs_moniker . parent ( ) { Some ( m ) => m , None => { return Err ( ModelError :: capability_discovery_error ( format_err ! ( " " ) ) ) } } ; let mut pos = WalkPosition { capability : ComponentCapability :: Use ( UseDecl :: Storage ( use_decl . clone ( ) ) ) , last_child_moniker : use_abs_moniker . path ( ) . last ( ) . map ( | c | c . clone ( ) ) , moniker : Some ( parent_moniker ) , } ; let source = walk_offer_chain ( model , & mut pos ) . await ? ; let ( storage_decl , storage_decl_moniker ) = match source { Some ( CapabilitySource :: StorageDecl ( decl , moniker ) ) => ( decl , moniker ) , _ => { return Err ( ModelError :: capability_discovery_error ( format_err ! ( " " ) ) ) } } ; let relative_moniker = RelativeMoniker :: from_absolute ( & storage_decl_moniker , & use_abs_moniker ) ; // Find the path and source of the directory consumed by the storage capability. let ( dir_source_path , dir_source_moniker ) = match storage_decl . source { StorageDirectorySource :: Self_ => ( storage_decl . source_path , storage_decl_moniker ) , StorageDirectorySource :: Realm => { let capability = ComponentCapability :: Storage ( storage_decl ) ; let source = find_capability_source ( model , capability , & storage_decl_moniker ) . await ? ; match source { CapabilitySource :: Component { capability , source_moniker } => { ( capability . source_path ( ) . unwrap ( ) . clone ( ) , source_moniker ) } _ => { return Err ( ModelError :: capability_discovery_error ( format_err ! ( " " ) ) ) } } } StorageDirectorySource :: Child ( ref name ) => { let mut pos = { let partial = PartialMoniker :: new ( name . to_string ( ) , None ) ; let storage_decl_realm = model . look_up_realm ( & storage_decl_moniker ) . await ? ; let realm_state = storage_decl_realm . lock_state ( ) . await ; let realm_state = realm_state . as_ref ( ) . expect ( " " ) ; let moniker = Some ( realm_state . extend_moniker_with ( & storage_decl_moniker , & partial ) . ok_or ( ModelError :: capability_discovery_error ( format_err ! ( " " partial pos moniker ( ) clone ( ) ) ) , ) ? ) ; let capability = ComponentCapability :: Storage ( storage_decl ) ; WalkPosition { capability , last_child_moniker : None , moniker } } ; match walk_expose_chain ( model , & mut pos ) . await ? { CapabilitySource :: Component { capability , source_moniker } => { ( capability . source_path ( ) . unwrap ( ) . clone ( ) , source_moniker ) } _ => { return Err ( ModelError :: capability_discovery_error ( format_err ! ( " " ) ) ) } } } } ; Ok ( ( dir_source_moniker , dir_source_path , relative_moniker ) ) }
Assuming `use_decl` is a UseStorage declaration, returns information about the source of the
storage capability, including:
 AbsoluteMoniker of the component hosting the backing directory capability
 Path to the backing directory capability
 Relative moniker between the backing directory component and the consumer, which identifies
the isolated storage directory.
Assuming ` use_decl ` is a UseStorage declaration returns information about the source of the storage capability including : AbsoluteMoniker of the component hosting the backing directory capability Path to the backing directory capability Relative moniker between the backing directory component and the consumer which identifies the isolated storage directory .
model
&'a Model
use_decl
&'a UseStorageDecl
use_abs_moniker
AbsoluteMoniker