Skip to main content

SourceProvider

Trait SourceProvider 

Source
pub trait SourceProvider {
    // Required methods
    fn resolve_path(
        &self,
        from: &Path,
        import_path: &str,
    ) -> Result<PathBuf, SourceError>;
    fn read_source(&self, path: &Path) -> Result<String, SourceError>;

    // Provided method
    fn derive_namespace(&self, import_path: &Path) -> Result<Id, SourceError> { ... }
}
Expand description

Abstraction over file I/O for the import resolver.

Implementations provide environment-specific file resolution and reading. The trait is object-safe so the resolver can use &dyn SourceProvider.

Required Methods§

Source

fn resolve_path( &self, from: &Path, import_path: &str, ) -> Result<PathBuf, SourceError>

Resolve an import path relative to the importing file.

The implementation must:

  1. Determine the directory of from (the importing file).
  2. Join it with import_path.
  3. Append the .orr extension.
  4. Return a normalized/canonical path for deduplication.
§Arguments
  • from — Path of the file containing the import statement.
  • import_path — The raw path string from source (e.g., "shared/styles").
§Errors

Returns SourceError if the path cannot be resolved.

Source

fn read_source(&self, path: &Path) -> Result<String, SourceError>

Read the source text of a file at the given path.

The path argument should be a value previously returned by resolve_path.

§Errors

Returns SourceError if the file cannot be read.

Provided Methods§

Source

fn derive_namespace(&self, import_path: &Path) -> Result<Id, SourceError>

Derives a namespace Id from an import path.

The default implementation extracts the final component’s file stem (e.g. shared/stylesstyles, ../common/base.orrbase).

§Arguments
  • import_path — The import path as a Path reference.
§Errors

Returns SourceError if a valid namespace name cannot be derived from the import path (e.g. the path has no file stem or contains non-UTF-8 characters).

Implementations on Foreign Types§

Source§

impl<P: SourceProvider> SourceProvider for &P

Blanket implementation that delegates all SourceProvider methods through a shared reference.

This allows &P to satisfy a P: SourceProvider bound.

Source§

fn resolve_path( &self, from: &Path, import_path: &str, ) -> Result<PathBuf, SourceError>

Source§

fn read_source(&self, path: &Path) -> Result<String, SourceError>

Source§

fn derive_namespace(&self, import_path: &Path) -> Result<Id, SourceError>

Implementors§