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::*;
|
2020-09-25 10:59:21 +08:00
|
|
|
|
|
|
|
mod collection;
|
2021-11-29 10:17:04 +08:00
|
|
|
mod dummy;
|
2020-09-25 10:59:21 +08:00
|
|
|
mod file;
|
2021-11-29 10:17:04 +08:00
|
|
|
mod stat;
|
2020-09-25 10:59:21 +08:00
|
|
|
|
2021-11-29 10:17:04 +08:00
|
|
|
pub use collection::ModuleResolversCollection;
|
|
|
|
pub use dummy::DummyModuleResolver;
|
2020-09-25 10:59:21 +08:00
|
|
|
#[cfg(not(feature = "no_std"))]
|
2022-01-12 08:12:28 +08:00
|
|
|
#[cfg(not(target_family = "wasm"))]
|
2020-09-25 10:59:21 +08:00
|
|
|
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,
|
2021-04-02 12:34:39 +08:00
|
|
|
source_path: Option<&str>,
|
2020-09-25 10:59:21 +08:00
|
|
|
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).
|
|
|
|
///
|
2021-12-09 12:49:12 +08:00
|
|
|
/// # 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,
|
2021-04-02 12:34:39 +08:00
|
|
|
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
|
|
|
}
|
2020-09-25 10:59:21 +08:00
|
|
|
}
|