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§
Sourcefn resolve_path(
&self,
from: &Path,
import_path: &str,
) -> Result<PathBuf, SourceError>
fn resolve_path( &self, from: &Path, import_path: &str, ) -> Result<PathBuf, SourceError>
Resolve an import path relative to the importing file.
The implementation must:
- Determine the directory of
from(the importing file). - Join it with
import_path. - Append the
.orrextension. - Return a normalized/canonical path for deduplication.
§Arguments
from— Path of the file containing theimportstatement.import_path— The raw path string from source (e.g.,"shared/styles").
§Errors
Returns SourceError if the path cannot be resolved.
Sourcefn read_source(&self, path: &Path) -> Result<String, SourceError>
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§
Sourcefn derive_namespace(&self, import_path: &Path) -> Result<Id, SourceError>
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/styles → styles, ../common/base.orr → base).
§Arguments
import_path— The import path as aPathreference.
§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.
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.