rhai/src/module/resolvers/mod.rs

55 lines
1.5 KiB
Rust
Raw Normal View History

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-12-26 06:05:57 +01:00
mod dummy;
pub use dummy::DummyModuleResolver;
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")))]
mod file;
#[cfg(not(feature = "no_std"))]
2021-02-19 08:50:48 +01:00
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
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,
source_path: Option<&str>,
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)]
2021-06-12 16:47:43 +02:00
#[must_use]
2021-01-09 09:52:22 +01:00
fn resolve_ast(
&self,
engine: &Engine,
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
}
}