2020-11-16 16:10:14 +01:00
|
|
|
use crate::fn_native::SendSync;
|
2021-01-09 09:52:22 +01:00
|
|
|
use crate::{Engine, EvalAltResult, Module, Position, Shared, AST};
|
2021-04-17 09:15:54 +02:00
|
|
|
#[cfg(feature = "no_std")]
|
|
|
|
use std::prelude::v1::*;
|
2020-09-25 04:59:21 +02:00
|
|
|
|
2020-12-26 06:05:57 +01:00
|
|
|
mod dummy;
|
|
|
|
pub use dummy::DummyModuleResolver;
|
|
|
|
|
2020-09-25 04:59:21 +02:00
|
|
|
mod collection;
|
|
|
|
pub use collection::ModuleResolversCollection;
|
|
|
|
|
|
|
|
#[cfg(not(feature = "no_std"))]
|
2021-02-19 08:50:48 +01:00
|
|
|
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
2020-09-25 04:59:21 +02:00
|
|
|
mod file;
|
|
|
|
|
|
|
|
#[cfg(not(feature = "no_std"))]
|
2021-02-19 08:50:48 +01:00
|
|
|
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
2020-09-25 04:59:21 +02:00
|
|
|
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,
|
2021-04-02 06:34:39 +02:00
|
|
|
source_path: Option<&str>,
|
2020-09-25 04:59:21 +02:00
|
|
|
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
|
|
|
|
2021-01-11 16:09:33 +01:00
|
|
|
/// Resolve an `AST` based on a path string.
|
2021-01-09 09:52:22 +01:00
|
|
|
///
|
|
|
|
/// 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,
|
2021-04-02 06:34:39 +02:00
|
|
|
source_path: Option<&str>,
|
2021-01-09 09:52:22 +01:00
|
|
|
path: &str,
|
|
|
|
pos: Position,
|
2021-01-09 16:26:50 +01:00
|
|
|
) -> Option<Result<AST, Box<EvalAltResult>>> {
|
|
|
|
None
|
2021-01-09 09:52:22 +01:00
|
|
|
}
|
2020-09-25 04:59:21 +02:00
|
|
|
}
|