/// 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>(
    use_decl: &'a UseStorageDecl,
    target_realm: &'a Arc<Realm>,
) -> Result<(Option<Arc<Realm>>, CapabilityPath, RelativeMoniker, CapabilityState), ModelError> {
    // Walk the offer chain to find the storage decl
    let parent_realm =
        target_realm.try_get_parent()?.ok_or(ModelError::capability_discovery_error(format!(
            "Storage capabilities cannot come from component manager's namespace."
        )))?;
    // Storage capabilities are always require rw rights to be valid so this must be
    // explicitly encoded into its starting walk state.
    let capability = ComponentCapability::Use(UseDecl::Storage(use_decl.clone()));
    let cap_state = CapabilityState::new(&capability);
    let mut pos = WalkPosition {
        capability,
        cap_state,
        last_child_moniker: target_realm.abs_moniker.path().last().map(|c| c.clone()),
        realm: Some(parent_realm),
    };
    let source = walk_offer_chain(&mut pos).await?;
    let (storage_decl, source_realm) = match source {
        Some(CapabilitySource::StorageDecl(decl, realm)) => (decl, realm.upgrade()?),
        _ => {
            return Err(ModelError::capability_discovery_error(format!(
                "Storage capability must come from a storage declaration."
            )))
        }
    };
    let relative_moniker =
        RelativeMoniker::from_absolute(&source_realm.abs_moniker, &target_realm.abs_moniker);
    // Find the path and source of the directory consumed by the storage capability.
    let (dir_source_path, dir_source_realm, cap_state) = match storage_decl.source {
        StorageDirectorySource::Self_ => {
            (storage_decl.source_path, Some(source_realm), pos.cap_state)
        }
        StorageDirectorySource::Realm => {
            let capability = ComponentCapability::Storage(storage_decl);
            let (source, cap_state) = find_capability_source(capability, &source_realm).await?;
            match source {
                CapabilitySource::Component { capability, realm } => {
                    (capability.source_path().unwrap().clone(), Some(realm.upgrade()?), cap_state)
                }
                CapabilitySource::Framework { capability, scope_moniker: None } => {
                    (capability.path().unwrap().clone(), None, cap_state)
                }
                CapabilitySource::Framework { scope_moniker: Some(_), .. } => panic!(
                    "using scoped framework capabilities for storage declarations is unsupported"
                ),
                CapabilitySource::StorageDecl(..) => {
                    panic!("storage directory sources can't come from storage declarations")
                }
            }
        }
        StorageDirectorySource::Child(ref name) => {
            let mut pos = {
                let partial = PartialMoniker::new(name.to_string(), None);
                let realm_state = source_realm.lock_resolved_state().await?;
                let child_realm = realm_state.get_live_child_realm(&partial).ok_or(
                    ModelError::capability_discovery_error(format!(
                        "The directory backing storage capability `{}` at `{}` is sourced from \
                        child `{}`, but this child does not exist.",
                        storage_decl.name, source_realm.abs_moniker, partial,
                    )),
                )?;
                let capability = ComponentCapability::Storage(storage_decl);
                WalkPosition {
                    capability,
                    cap_state: pos.cap_state.clone(),
                    last_child_moniker: None,
                    realm: Some(child_realm),
                }
            };
            let source = walk_expose_chain(&mut pos).await?;
            match source {
                CapabilitySource::Component { capability, realm } => (
                    capability.source_path().unwrap().clone(),
                    Some(realm.upgrade()?),
                    pos.cap_state,
                ),
                _ => {
                    return Err(ModelError::capability_discovery_error(format!(
                        "Storage capability backing directory must be provided by a component."
                    )))
                }
            }
        }
    };
    Ok((dir_source_realm, dir_source_path, relative_moniker, cap_state))
}
async fn route_storage_capability < ' a > ( use_decl : & ' a UseStorageDecl , target_realm : & ' a Arc < Realm > , ) -> Result < ( Option < Arc < Realm > > , CapabilityPath , RelativeMoniker , CapabilityState ) , ModelError > { // Walk the offer chain to find the storage decl let parent_realm = target_realm . try_get_parent ( ) ? . ok_or ( ModelError :: capability_discovery_error ( format ! ( " " ) ) ) ? ; // Storage capabilities are always require rw rights to be valid so this must be // explicitly encoded into its starting walk state. let capability = ComponentCapability :: Use ( UseDecl :: Storage ( use_decl . clone ( ) ) ) ; let cap_state = CapabilityState :: new ( & capability ) ; let mut pos = WalkPosition { capability , cap_state , last_child_moniker : target_realm . abs_moniker . path ( ) . last ( ) . map ( | c | c . clone ( ) ) , realm : Some ( parent_realm ) , } ; let source = walk_offer_chain ( & mut pos ) . await ? ; let ( storage_decl , source_realm ) = match source { Some ( CapabilitySource :: StorageDecl ( decl , realm ) ) => ( decl , realm . upgrade ( ) ? ) , _ => { return Err ( ModelError :: capability_discovery_error ( format ! ( " " ) ) ) } } ; let relative_moniker = RelativeMoniker :: from_absolute ( & source_realm . abs_moniker , & target_realm . abs_moniker ) ; // Find the path and source of the directory consumed by the storage capability. let ( dir_source_path , dir_source_realm , cap_state ) = match storage_decl . source { StorageDirectorySource :: Self_ => { ( storage_decl . source_path , Some ( source_realm ) , pos . cap_state ) } StorageDirectorySource :: Realm => { let capability = ComponentCapability :: Storage ( storage_decl ) ; let ( source , cap_state ) = find_capability_source ( capability , & source_realm ) . await ? ; match source { CapabilitySource :: Component { capability , realm } => { ( capability . source_path ( ) . unwrap ( ) . clone ( ) , Some ( realm . upgrade ( ) ? ) , cap_state ) } CapabilitySource :: Framework { capability , scope_moniker : None } => { ( capability . path ( ) . unwrap ( ) . clone ( ) , None , cap_state ) } CapabilitySource :: Framework { scope_moniker : Some ( _ ) , .. } => panic ! ( " " ) , CapabilitySource :: StorageDecl ( .. ) => { panic ! ( " " ) } } } StorageDirectorySource :: Child ( ref name ) => { let mut pos = { let partial = PartialMoniker :: new ( name . to_string ( ) , None ) ; let realm_state = source_realm . lock_resolved_state ( ) . await ? ; let child_realm = realm_state . get_live_child_realm ( & partial ) . ok_or ( ModelError :: capability_discovery_error ( format ! ( " \
 " storage_decl name source_realm abs_moniker partial ) ) , ) ? ; let capability = ComponentCapability :: Storage ( storage_decl ) ; WalkPosition { capability , cap_state : pos . cap_state . clone ( ) , last_child_moniker : None , realm : Some ( child_realm ) , } } ; let source = walk_expose_chain ( & mut pos ) . await ? ; match source { CapabilitySource :: Component { capability , realm } => ( capability . source_path ( ) . unwrap ( ) . clone ( ) , Some ( realm . upgrade ( ) ? ) , pos . cap_state , ) , _ => { return Err ( ModelError :: capability_discovery_error ( format ! ( " " ) ) ) } } } } ; Ok ( ( dir_source_realm , dir_source_path , relative_moniker , cap_state ) ) }
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 .
use_decl
&'a UseStorageDecl
target_realm
&'a Arc<Realm>