Skip to main content

Aether

Struct Aether 

Source
pub struct Aether { /* private fields */ }
Expand description

主要的 Aether 引擎结构体

Implementations§

Source§

impl Aether

Source

pub fn cache_stats(&self) -> CacheStats

获取缓存统计信息

Source

pub fn clear_cache(&mut self)

清空缓存

Source

pub fn set_optimization( &mut self, constant_folding: bool, dead_code: bool, tail_recursion: bool, )

设置优化选项

Source§

impl Aether

Source

pub fn new() -> Self

创建新的 Aether 引擎实例

用于 DSL 嵌入:IO 操作默认禁用以确保安全性。 使用 with_permissions() 或 with_all_permissions() 来启用 IO。

用于 CLI 使用:命令行工具默认使用 with_all_permissions()。

Source

pub fn with_permissions(permissions: IOPermissions) -> Self

使用自定义 IO 权限创建新的 Aether 引擎

Source

pub fn with_all_permissions() -> Self

创建启用所有 IO 权限的新 Aether 引擎

Source

pub fn with_stdlib() -> Result<Self, String>

创建预加载标准库的新 Aether 引擎。

标准库模块为纯计算(内嵌源码),加载不需要 IO 权限—— 因此这里基于 Aether::new() 构建,不会静默授予文件读写能力; 需要 IO 的宿主请显式 with_permissions(...)。

Source§

impl Aether

Source

pub fn attach_debugger( &mut self, state: Rc<RefCell<DebuggerState>>, hook: Box<dyn FnMut(&mut Evaluator) -> bool>, )

挂载调试器:与 DebuggerSession 共享同一状态实例, 命中断点/步进时回调 hook(在其中运行调试 REPL),返回 true 终止程序

Source

pub fn detach_debugger(&mut self)

卸载调试器

Source

pub fn set_source_file(&mut self, file: String)

设置当前源文件(供调试器按 file:line 匹配断点;文件运行器应在求值前调用)

Source

pub fn lookup_variable(&self, name: &str) -> Option<Value>

按作用域链查找变量(供调试器在暂停时检查变量值)

Source

pub fn evaluator_mut(&mut self) -> &mut Evaluator

访问内部求值器(调试器命令需要读取调用栈深度、当前源文件等状态)

Source§

impl Aether

Source

pub fn eval(&mut self, code: &str) -> Result<Value, String>

求值 Aether 代码并返回结果

Source

pub fn eval_report(&mut self, code: &str) -> Result<Value, ErrorReport>

求值 Aether 代码并在失败时返回结构化的错误报告。

这适用于需要机器可读诊断的集成。

Source

pub fn set_module_resolver(&mut self, resolver: Box<dyn ModuleResolver>)

配置用于 Import/Export 的模块解析器。

默认情况下(DSL 嵌入),解析器出于安全考虑被禁用。

Source

pub fn push_import_base(&mut self, module_id: String, base_dir: Option<PathBuf>)

推送用于解析相对导入的基础目录上下文。

这通常由基于文件的运行器(CLI)在调用 eval() 之前使用。

Source

pub fn pop_import_base(&mut self)

弹出最近的基础目录上下文。

Source

pub fn eval_file(&mut self, path: impl AsRef<Path>) -> Result<Value, String>

从文件路径求值 Aether 脚本。

这是一个便利包装器,它:

  • 读取文件
  • 推送导入基础上下文(module_id = 规范路径;base_dir = 父目录)
  • 求值代码
  • 弹出导入基础上下文

注意:这不会启用任何模块解析器。为了 DSL 安全性,除非您明确调用 set_module_resolver(...),否则模块加载保持禁用状态。

Source

pub fn eval_file_report( &mut self, path: impl AsRef<Path>, ) -> Result<Value, ErrorReport>

从文件路径求值 Aether 脚本,在失败时返回结构化的错误报告。

Source

pub fn set_global(&mut self, name: &str, value: Value)

从宿主应用程序设置全局变量,而不使用 eval()。

当您已经有 Rust 端数据并希望将其作为 Value 注入脚本环境时,这很有用。

Source

pub fn reset_env(&mut self)

重置运行时环境(变量/函数),同时保持内置函数注册。

注意:这会清除通过 eval() 引入的任何内容(包括 stdlib 代码)。

Source

pub fn with_isolated_scope<R>( &mut self, f: impl FnOnce(&mut Aether) -> Result<R, String>, ) -> Result<R, String>

在隔离的子作用域内运行闭包。

在闭包内注入或定义的所有变量/函数将在返回时被丢弃,而外部环境被保留。

这是为 “DSL 宿主” 场景设计的:注入 Rust 数据 + 加载每请求的 Aether 函数(例如从 DB)+ 运行脚本,而不跨请求污染。

Source§

impl Aether

Source

pub fn with_limits(self, limits: ExecutionLimits) -> Self

使用执行限制创建新的 Aether 引擎

Source

pub fn set_limits(&mut self, limits: ExecutionLimits)

设置执行限制

Source

pub fn limits(&self) -> &ExecutionLimits

获取当前执行限制

Source

pub fn set_bigint_threshold(&mut self, threshold: usize)

设置大整数切换阈值。

整数字面量位数超过该阈值时,解析期会将其构造为任意精度 BigInteger。 默认值 15(接近 f64 精度极限)。

注意:AST 缓存按源码文本命中,修改阈值后已在缓存中的程序不会重新解析; 如需立即生效可配合 reset_env() 或对新代码使用。

Source

pub fn bigint_threshold(&self) -> usize

获取当前大整数切换阈值

Source§

impl Aether

Source

pub fn load_stdlib_module(&mut self, module_name: &str) -> Result<(), String>

加载特定的标准库模块

可用模块见 stdlib::ALL_MODULES(string_utils、array_utils、 validation、datetime、testing、set、queue、stack、heap、sorting、 json、csv、functional、cli_utils、text_template、regex_utils)。 未知模块名返回 Err。

Source

pub fn load_all_stdlib(&mut self) -> Result<(), String>

加载所有标准库模块

Source

pub fn with_stdlib_module(self, module_name: &str) -> Result<Self, String>

加载特定标准库模块(可链式调用),未知模块名报错

let engine = Aether::new()
    .with_stdlib_module("string_utils")
    .expect("模块加载失败");
Source§

impl Aether

Source

pub fn take_trace(&mut self) -> Vec<String>

清空内存中的 TRACE 缓冲区。

这是为 DSL 安全调试设计的:脚本调用 TRACE(...) 来记录 值,宿主应用程序通过此方法带外读取它们。

Source

pub fn clear_trace(&mut self)

清除 TRACE 缓冲区而不返回它。

Source

pub fn trace_records(&self) -> Vec<TraceEntry>

获取所有结构化的跟踪条目

返回带有级别、类别、时间戳等的结构化跟踪条目向量。

Source

pub fn trace_by_level(&self, level: TraceLevel) -> Vec<TraceEntry>

按级别过滤跟踪条目

Source

pub fn trace_by_category(&self, category: &str) -> Vec<TraceEntry>

按类别过滤跟踪条目

Source

pub fn trace_by_label(&self, label: &str) -> Vec<TraceEntry>

按标签过滤跟踪条目

Source

pub fn trace_filter(&self, filter: &TraceFilter) -> Vec<TraceEntry>

对跟踪条目应用复杂过滤器

Source

pub fn trace_stats(&self) -> TraceStats

获取跟踪统计信息

返回关于跟踪条目的统计信息,包括按级别和类别的计数。

Source

pub fn set_trace_buffer_size(&mut self, size: usize)

设置 TRACE 缓冲区大小

这将设置 TRACE 缓冲区可以存储的最大条目数。 如果新大小小于当前条目数,多余的条目将被从缓冲区前端移除。

Source

pub fn step_count(&self) -> usize

获取当前顶级执行的 step 计数。

该计数在每次调用 eval(...) / eval_report(...)(以及它们的文件包装器)开始时被重置。

说明:step 目前按“语句级”计数(每求值一条语句 +1)。

Trait Implementations§

Source§

impl Default for Aether

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !Freeze for Aether

§

impl !RefUnwindSafe for Aether

§

impl !Send for Aether

§

impl !Sync for Aether

§

impl !UnwindSafe for Aether

§

impl Forget for Aether

§

impl Move for Aether

§

impl Unpin for Aether

§

impl UnsafeUnpin for Aether

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.