50 lines
1.3 KiB
Rust
Raw Normal View History

2021-11-13 22:36:23 +08:00
use crate::func::native::SendSync;
2021-12-25 23:49:14 +08:00
use crate::{Engine, Module, Position, RhaiResultOf, Shared, AST};
2021-04-17 15:15:54 +08:00
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
mod collection;
2021-11-29 10:17:04 +08:00
mod dummy;
mod file;
2021-11-29 10:17:04 +08:00
mod stat;
2021-11-29 10:17:04 +08:00
pub use collection::ModuleResolversCollection;
pub use dummy::DummyModuleResolver;
#[cfg(not(feature = "no_std"))]
2022-01-12 08:12:28 +08:00
#[cfg(not(target_family = "wasm"))]
pub use file::FileModuleResolver;
pub use stat::StaticModuleResolver;
/// Trait that encapsulates a module resolution service.
pub trait ModuleResolver: SendSync {
/// Resolve a module based on a path string.
fn resolve(
&self,
engine: &Engine,
source_path: Option<&str>,
path: &str,
pos: Position,
2021-12-25 23:49:14 +08:00
) -> RhaiResultOf<Shared<Module>>;
2021-01-09 16:52:22 +08:00
2021-01-11 23:09:33 +08:00
/// Resolve an `AST` based on a path string.
2021-01-09 16:52:22 +08:00
///
/// Returns [`None`] (default) if such resolution is not supported
/// (e.g. if the module is Rust-based).
///
/// # WARNING - Low Level API
2021-01-09 16:52:22 +08:00
///
/// Override the default implementation of this method if the module resolver
/// serves modules based on compiled Rhai scripts.
#[allow(unused_variables)]
2021-06-12 22:47:43 +08:00
#[must_use]
2021-01-09 16:52:22 +08:00
fn resolve_ast(
&self,
engine: &Engine,
source_path: Option<&str>,
2021-01-09 16:52:22 +08:00
path: &str,
pos: Position,
2021-12-25 23:49:14 +08:00
) -> Option<RhaiResultOf<AST>> {
2021-01-09 23:26:50 +08:00
None
2021-01-09 16:52:22 +08:00
}
}