PackageLoader

Trait PackageLoader 

Source
pub trait PackageLoader {
    // Required method
    fn load(&mut self, import: &mut Import) -> Result<Sources, String>;
}
Expand description

Trait to load packages from various sources.

Required Methods§

Source

fn load(&mut self, import: &mut Import) -> Result<Sources, String>

Load a package specified by the import parameter.

§Parameters
  • import: A mutable reference to an Import structure, which contains:
    • path: The path to the package or directory to be imported.
    • imp_type: The type of import, which can specify a single name, a list of names, or all names in a path.
    • relative: A boolean indicating if the path is relative to the current directory.
    • src: A BoundSource to be updated with the names of the located files.
§Behavior

The load method is responsible for locating and loading the requested package(s). The loaded packages are returned as a Sources map, where the key is the package name and the value is its content. Implementers must:

  • Track already loaded sources to avoid loading and returning them again.
  • Update import.src with the names of the found packages, even if they are not included in the Sources map.

The implementation should handle the following import types:

  • Single: Load a specific file by its name.
  • List: Load a list of specified files or names from a specific file.
  • Glob: Load all files in a directory or all names from a specific file.

Implementors§