fn load_cached_module(
        &self,
        store: &Store,
        cache_dir: PathBuf,
    ) -> anyhow::Result<wasmtime::Module> {
        log::trace!("Module::load_cached_module: {}", &self.module);
        let canonical_path = match Url::parse(self.module.as_str()) {
            Err(e) => {
                log::debug!(
                    "Error parsing module URI {}. Assuming this is a local file.",
                    e
                );
                PathBuf::from(self.module.as_str())
            }
            Ok(uri) => match uri.scheme() {
                "file" => match uri.to_file_path() {
                    Ok(p) => p,
                    Err(e) => anyhow::bail!("Cannot get path to file: {:#?}", e),
                },
                "bindle" => cache_dir.join(bindle_cache_key(&uri)),
                "parcel" => cache_dir.join(uri.path()), // parcel:SHA256 becomes cache_dir/SHA256
                "oci" => cache_dir.join(self.hash_name()),
                s => {
                    log::error!(
                        "Module::load_cached_module: unknown scheme {} in module {}",
                        s,
                        &self.module
                    );
                    anyhow::bail!("Unknown scheme {}", s)
                }
            },
        };
        log::trace!(
            "Module::load_cached_module: canonical_path={:?}",
            canonical_path
        );

        // If there is a module at this path, load it.
        // Right now, _any_ problem loading the module will result in us trying to
        // re-fetch it.
        match wasmtime::Module::from_file(store.engine(), canonical_path) {
            Ok(module) => Ok(module),
            Err(_e) => {
                log::debug!(
                    "module cache miss. Loading module {} from remote.",
                    self.module
                );
                // TODO: This could be reallllllllly dangerous as we are for sure going to block at this
                // point on this current thread. This _should_ be ok given that we run this as a
                // spawn_blocking, but those sound like famous last words waiting to happen. Refactor this
                // sooner rather than later
                futures::executor::block_on(self.load_module(&store, cache_dir))
            }
        }
    }
/// Load a cached module from the filesystem.
///
/// This is synchronous right now because Wasmtime on the runner needs to be run synchronously.
/// This will change when the new version of Wasmtime adds Send + Sync to all the things.
/// Then we can just do `load_module` or refactor this to be async.
Load a cached module from the filesystem.
This is synchronous right now because Wasmtime on the runner needs to be run synchronously.
This will change when the new version of Wasmtime adds Send + Sync to all the things.
Then we can just do `load_module` or refactor this to be async.
Load a cached module from the filesystem . This is synchronous right now because Wasmtime on the runner needs to be run synchronously . This will change when the new version of Wasmtime adds Send + Sync to all the things . Then we can just do ` load_module ` or refactor this to be async .
fn load_cached_module(
        &self,
        store: &Store,
        cache_dir: PathBuf,
    ) -> anyhow::Result<wasmtime::Module> {
        log::trace!("Module::load_cached_module: {}", &self.module);
        let canonical_path = match Url::parse(self.module.as_str()) {
            Err(e) => {
                log::debug!(
                    "Error parsing module URI {}. Assuming this is a local file.",
                    e
                );
                PathBuf::from(self.module.as_str())
            }
            Ok(uri) => match uri.scheme() {
                "file" => match uri.to_file_path() {
                    Ok(p) => p,
                    Err(e) => anyhow::bail!("Cannot get path to file: {:#?}", e),
                },
                "bindle" => cache_dir.join(bindle_cache_key(&uri)),
                "parcel" => cache_dir.join(uri.path()), // parcel:SHA256 becomes cache_dir/SHA256
                "oci" => cache_dir.join(self.hash_name()),
                s => {
                    log::error!(
                        "Module::load_cached_module: unknown scheme {} in module {}",
                        s,
                        &self.module
                    );
                    anyhow::bail!("Unknown scheme {}", s)
                }
            },
        };
        log::trace!(
            "Module::load_cached_module: canonical_path={:?}",
            canonical_path
        );
        // If there is a module at this path, load it.
        // Right now, _any_ problem loading the module will result in us trying to
        // re-fetch it.
        match wasmtime::Module::from_file(store.engine(), canonical_path) {
            Ok(module) => Ok(module),
            Err(_e) => {
                log::debug!(
                    "module cache miss. Loading module {} from remote.",
                    self.module
                );
                // TODO: This could be reallllllllly dangerous as we are for sure going to block at this
                // point on this current thread. This _should_ be ok given that we run this as a
                // spawn_blocking, but those sound like famous last words waiting to happen. Refactor this
                // sooner rather than later
                futures::executor::block_on(self.load_module(&store, cache_dir))
            }
        }
    }
fn load_cached_module ( & self , store : & Store , cache_dir : PathBuf , ) -> anyhow :: Result < wasmtime :: Module > { log :: trace ! ( " " self module ) ; let canonical_path = match Url :: parse ( self . module . as_str ( ) ) { Err ( e ) => { log :: debug ! ( " " e ) ; PathBuf :: from ( self . module . as_str ( ) ) } Ok ( uri ) => match uri . scheme ( ) { " " => match uri . to_file_path ( ) { Ok ( p ) => p , Err ( e ) => anyhow :: bail ! ( " " e ) , } , " " => cache_dir . join ( bindle_cache_key ( & uri ) ) , " " => cache_dir . join ( uri . path ( ) ) , // parcel:SHA256 becomes cache_dir/SHA256 " " => cache_dir . join ( self . hash_name ( ) ) , s => { log :: error ! ( " " s self module ) ; anyhow :: bail ! ( " " s ) } } , } ; log :: trace ! ( " " canonical_path ) ; // If there is a module at this path, load it. // Right now, _any_ problem loading the module will result in us trying to // re-fetch it. match wasmtime :: Module :: from_file ( store . engine ( ) , canonical_path ) { Ok ( module ) => Ok ( module ) , Err ( _e ) => { log :: debug ! ( " " self module ) ; // TODO: This could be reallllllllly dangerous as we are for sure going to block at this // point on this current thread. This _should_ be ok given that we run this as a // spawn_blocking, but those sound like famous last words waiting to happen. Refactor this // sooner rather than later futures :: executor :: block_on ( self . load_module ( & store , cache_dir ) ) } } }
Load a cached module from the filesystem.
Load a cached module from the filesystem .
&self
store
&Store
cache_dir
PathBuf