pub trait SourceResolver {
// Required method
fn get_contents(&self, path: &Path) -> Result<Arc<str>, SourceLoadError>;
// Provided methods
fn resolve_raw_path(
&self,
path: &Path,
_included_from: Option<&Path>,
) -> PathBuf { ... }
fn canonicalize(&self, path: &Path) -> Result<PathBuf, SourceLoadError> { ... }
}
Expand description
A trait that abstracts resolving a path.
In general, paths are resolved through the filesystem; however if you are doing something fancy (such as keeping your source files in memory) you can pass a closure or another custom implementation of this trait into the appropriate parse functions.
If you need a custom resolver, you can either implement this trait for some
custom type, or you can use a closure with the signature,
|&Path| -> Result<String, SourceLoadError>
.
Required Methods§
Sourcefn get_contents(&self, path: &Path) -> Result<Arc<str>, SourceLoadError>
fn get_contents(&self, path: &Path) -> Result<Arc<str>, SourceLoadError>
Return the contents of the utf-8 encoded file at the provided path.
Provided Methods§
Sourcefn resolve_raw_path(
&self,
path: &Path,
_included_from: Option<&Path>,
) -> PathBuf
fn resolve_raw_path( &self, path: &Path, _included_from: Option<&Path>, ) -> PathBuf
Given a raw path (the $path
in include($path)
), return the path to load.
The final path may differ based on which file the include statement occurs
in; the path of the including file (if this is not the root source) is
passed as the second argument.
See including files for more information.
The default implementation returns the path
argument, unchanged.
Sourcefn canonicalize(&self, path: &Path) -> Result<PathBuf, SourceLoadError>
fn canonicalize(&self, path: &Path) -> Result<PathBuf, SourceLoadError>
If necessary, canonicalize this path.
There are an unbounded number of ways to represent a given path;
fot instance, the path ./features.fea
may be equivalent to the path
./some_folder/../features.fea
or to ../../my/font/features.fea
.
This method is an opportunity to specify the canonical representaiton
of a path.