PathResolver

Trait PathResolver 

Source
pub trait PathResolver {
    // Required methods
    fn prefix(&self) -> &'static str;
    fn split_module_and_subpath(
        &self,
        full_path_after_prefix: &str,
    ) -> Result<(String, Option<String>), String>;
    fn resolve(&self, module_name: &str) -> Result<PathBuf, String>;
}
Expand description

A trait for language-specific path resolvers.

Implementations of this trait provide language-specific logic for resolving package/module names to filesystem paths.

Required Methods§

Source

fn prefix(&self) -> &'static str

The prefix used to identify paths for this resolver (e.g., “go:”, “js:”, “rust:”).

Source

fn split_module_and_subpath( &self, full_path_after_prefix: &str, ) -> Result<(String, Option<String>), String>

Splits the path string (after the prefix) into the core module/package identifier and an optional subpath.

For example, for Go:

  • “fmt” -> Ok((“fmt”, None))
  • “net/http” -> Ok((“net/http”, None)) // Stdlib multi-segment
  • “github.com/gin-gonic/gin” -> Ok((“github.com/gin-gonic/gin”, None))
  • “github.com/gin-gonic/gin/examples/basic” -> Ok((“github.com/gin-gonic/gin”, Some(“examples/basic”)))

For JavaScript:

  • “lodash” -> Ok((“lodash”, None))
  • “lodash/get” -> Ok((“lodash”, Some(“get”)))
  • “@types/node” -> Ok((“@types/node”, None))
  • “@types/node/fs” -> Ok((“@types/node”, Some(“fs”)))
§Arguments
  • full_path_after_prefix - The portion of the input path string that comes after the resolver’s prefix.
§Returns
  • Ok((String, Option<String>)) - A tuple containing the resolved module name and an optional subpath string.
  • Err(String) - An error message if the path format is invalid for this resolver.
Source

fn resolve(&self, module_name: &str) -> Result<PathBuf, String>

Resolves a package/module name to its filesystem location.

§Arguments
  • module_name - The package/module name to resolve (without any subpath)
§Returns
  • Ok(PathBuf) - The filesystem path where the package is located
  • Err(String) - An error message if resolution fails

Implementors§