rhai/src/module/resolvers/mod.rs

50 lines
1.3 KiB
Rust
Raw Normal View History

2021-11-13 15:36:23 +01:00
use crate::func::native::SendSync;
2021-12-25 16:49:14 +01:00
use crate::{Engine, Module, Position, RhaiResultOf, Shared, AST};
2021-04-17 09:15:54 +02:00
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
mod collection;
2021-11-29 03:17:04 +01:00
mod dummy;
mod file;
2021-11-29 03:17:04 +01:00
mod stat;
2021-11-29 03:17:04 +01:00
pub use collection::ModuleResolversCollection;
pub use dummy::DummyModuleResolver;
#[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;
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 16:49:14 +01:00
) -> RhaiResultOf<Shared<Module>>;
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).
///
/// # WARNING - Low Level API
2021-01-09 09:52:22 +01: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 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-12-25 16:49:14 +01:00
) -> Option<RhaiResultOf<AST>> {
2021-01-09 16:26:50 +01:00
None
2021-01-09 09:52:22 +01:00
}
}