ModuleLoader

Trait ModuleLoader 

Source
pub trait ModuleLoader:
    Debug
    + Send
    + Sync {
    // Required method
    fn load(&self, context: &mut RunContext<'_, '_>) -> Result<(), String>;

    // Provided methods
    fn pkg_info(&self) -> Option<&PkgInfo> { ... }
    fn prepare(
        &self,
        _local_dir: Option<&Path>,
        _update_mode: UpdateMode,
    ) -> Result<Option<Box<dyn ModuleLoader>>, String> { ... }
    fn get_resource(
        &self,
        _res_key: ResourceKey<'_>,
    ) -> Result<Resource, String> { ... }
    fn load_tokens(
        &self,
        _target: &MettaMod,
        _metta: Metta,
    ) -> Result<(), String> { ... }
}
Expand description

Implemented to supply a loader functions for MeTTa modules

A ModuleLoader is responsible for loading a MeTTa module through the API. Implementations of ModuleLoader can be used to define a module format or to supply programmatically defined modules

Required Methods§

Source

fn load(&self, context: &mut RunContext<'_, '_>) -> Result<(), String>

A function to load the module my making MeTTa API calls. This function will be called as a downstream consequence of Metta::load_module_at_path, Metta::load_module_direct, RunContext::load_module, or any other method that leads to the loading of modules

Provided Methods§

Source

fn pkg_info(&self) -> Option<&PkgInfo>

A function to access the PkgInfo struct of meta-data associated with a module

NOTE: Requires pkg_mgmt feature

Source

fn prepare( &self, _local_dir: Option<&Path>, _update_mode: UpdateMode, ) -> Result<Option<Box<dyn ModuleLoader>>, String>

Prepares a module for loading. This method is responsible for fetching resources from the network, performing build or pre-computation steps, or any other operations that only need to be performed once and then may be cached locally

If this method returns Ok(Some(_)) then the loader will be dropped and the returned loader will replace it.

NOTE: This method may become async in the future

FUTURE-QUESTION: Should “Fetch” and “Build” be separated? Currently they are lumped together into one interface but it may make sense to split them into separate entry points. I will keep them as one until the need arises.

Source

fn get_resource(&self, _res_key: ResourceKey<'_>) -> Result<Resource, String>

Returns a data blob containing a given named resource belonging to a module

Source

fn load_tokens(&self, _target: &MettaMod, _metta: Metta) -> Result<(), String>

Loads module’s tokens into target module. This method is used for both initial token loading and exporting module’s tokens into importing module.

Implementors§