rhai/src/module/resolvers/mod.rs

51 lines
1.3 KiB
Rust
Raw Normal View History

2020-11-16 16:10:14 +01:00
use crate::fn_native::SendSync;
use crate::stdlib::boxed::Box;
2021-01-09 09:52:22 +01:00
use crate::{Engine, EvalAltResult, Module, Position, Shared, AST};
2020-12-26 06:05:57 +01:00
mod dummy;
pub use dummy::DummyModuleResolver;
mod collection;
pub use collection::ModuleResolversCollection;
#[cfg(not(feature = "no_std"))]
#[cfg(not(target_arch = "wasm32"))]
mod file;
#[cfg(not(feature = "no_std"))]
#[cfg(not(target_arch = "wasm32"))]
pub use file::FileModuleResolver;
mod stat;
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,
path: &str,
pos: Position,
2020-11-07 16:33:21 +01:00
) -> Result<Shared<Module>, Box<EvalAltResult>>;
2021-01-09 09:52:22 +01:00
/// Resolve a module into an `AST` based on a path string.
///
/// Returns [`None`] (default) if such resolution is not supported
/// (e.g. if the module is Rust-based).
///
/// ## Low-Level API
///
/// Override the default implementation of this method if the module resolver
/// serves modules based on compiled Rhai scripts.
#[allow(unused_variables)]
fn resolve_ast(
&self,
engine: &Engine,
path: &str,
pos: Position,
) -> Result<Option<AST>, Box<EvalAltResult>> {
Ok(None)
}
}