// Load the `component_url` driver out of `dir` which should be the root directory
// of that component. Will return Ok(None) if `component_url` is a valid component
// but it's not a driver component.
Load the `component_url` driver out of `dir` which should be the root directory
of that component. Will return Ok(None) if `component_url` is a valid component
but it's not a driver component.
Load the ` component_url ` driver out of ` dir ` which should be the root directory of that component . Will return Ok ( None ) if ` component_url ` is a valid component but it ' s not a driver component .
async fn load_driver(
    dir: &fio::DirectoryProxy,
    component_url: url::Url,
) -> Result<Option<ResolvedDriver>, anyhow::Error> {
    let component = io_util::open_file(
        &dir,
        std::path::Path::new(
            component_url
                .fragment()
                .ok_or(anyhow::anyhow!("{}: URL is missing fragment", component_url.as_str()))?,
        ),
        fio::OPEN_RIGHT_READABLE,
    )?;
    let component: fsys::ComponentDecl = io_util::read_file_fidl(&component)
        .await
        .with_context(|| format!("{}: Failed to read component", component_url.as_str()))?;
    let component = component.fidl_into_native();
    let runner = match component.get_runner() {
        Some(r) => r,
        None => return Ok(None),
    };
    if runner.str() != "driver" {
        return Ok(None);
    }
    let bind_path = get_rules_string_value(&component, "bind")
        .ok_or(anyhow::anyhow!("{}: Missing bind path", component_url.as_str()))?;
    let bind = io_util::open_file(&dir, std::path::Path::new(&bind_path), fio::OPEN_RIGHT_READABLE)
        .with_context(|| format!("{}: Failed to open bind", component_url.as_str()))?;
    let bind = io_util::read_file_bytes(&bind)
        .await
        .with_context(|| format!("{}: Failed to read bind", component_url.as_str()))?;
    let bind = DecodedRules::new(bind)
        .with_context(|| format!("{}: Failed to parse bind", component_url.as_str()))?;
    let v1_driver_path = get_rules_string_value(&component, "compat");
    Ok(Some(ResolvedDriver {
        component_url: component_url,
        v1_driver_path: v1_driver_path,
        bind_rules: bind,
    }))
}
async fn load_driver ( dir : & fio :: DirectoryProxy , component_url : url :: Url , ) -> Result < Option < ResolvedDriver > , anyhow :: Error > { let component = io_util :: open_file ( & dir , std :: path :: Path :: new ( component_url . fragment ( ) . ok_or ( anyhow :: anyhow ! ( " " component_url as_str ( ) ) ) ? , ) , fio :: OPEN_RIGHT_READABLE , ) ? ; let component : fsys :: ComponentDecl = io_util :: read_file_fidl ( & component ) . await . with_context ( | | format ! ( " " component_url as_str ( ) ) ) ? ; let component = component . fidl_into_native ( ) ; let runner = match component . get_runner ( ) { Some ( r ) => r , None => return Ok ( None ) , } ; if runner . str ( ) != " " { return Ok ( None ) ; } let bind_path = get_rules_string_value ( & component , " " ) . ok_or ( anyhow :: anyhow ! ( " " component_url as_str ( ) ) ) ? ; let bind = io_util :: open_file ( & dir , std :: path :: Path :: new ( & bind_path ) , fio :: OPEN_RIGHT_READABLE ) . with_context ( | | format ! ( " " component_url as_str ( ) ) ) ? ; let bind = io_util :: read_file_bytes ( & bind ) . await . with_context ( | | format ! ( " " component_url as_str ( ) ) ) ? ; let bind = DecodedRules :: new ( bind ) . with_context ( | | format ! ( " " component_url as_str ( ) ) ) ? ; let v1_driver_path = get_rules_string_value ( & component , " " ) ; Ok ( Some ( ResolvedDriver { component_url : component_url , v1_driver_path : v1_driver_path , bind_rules : bind , } ) ) }
Load the `component_url` driver out of `dir` which should be the root directory
of that component.
Load the ` component_url ` driver out of ` dir ` which should be the root directory of that component .
dir
&fio::DirectoryProxy
component_url
url::Url