pub struct Aether { /* private fields */ }Expand description
Main Aether engine struct
Implementations§
Source§impl Aether
impl Aether
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Aether engine instance
For DSL embedding: IO operations are disabled by default for security.
Use with_permissions() or with_all_permissions() to enable IO.
For CLI usage: The command-line tool uses with_all_permissions() by default.
Sourcepub fn with_permissions(permissions: IOPermissions) -> Self
pub fn with_permissions(permissions: IOPermissions) -> Self
Create a new Aether engine with custom IO permissions
Sourcepub fn with_all_permissions() -> Self
pub fn with_all_permissions() -> Self
Create a new Aether engine with all IO permissions enabled
Sourcepub fn with_stdlib() -> Result<Self, String>
pub fn with_stdlib() -> Result<Self, String>
Create a new Aether engine with standard library preloaded
This creates an engine with all permissions and automatically loads all standard library modules (string_utils, array_utils, validation, datetime, testing).
Sourcepub fn load_stdlib_module(&mut self, module_name: &str) -> Result<(), String>
pub fn load_stdlib_module(&mut self, module_name: &str) -> Result<(), String>
Load a specific standard library module
Available modules: “string_utils”, “array_utils”, “validation”, “datetime”, “testing”
Sourcepub fn load_all_stdlib(&mut self) -> Result<(), String>
pub fn load_all_stdlib(&mut self) -> Result<(), String>
Load all standard library modules
Sourcepub fn with_stdlib_string_utils(self) -> Result<Self, String>
pub fn with_stdlib_string_utils(self) -> Result<Self, String>
Load string utilities module (chainable)
Sourcepub fn with_stdlib_array_utils(self) -> Result<Self, String>
pub fn with_stdlib_array_utils(self) -> Result<Self, String>
Load array utilities module (chainable)
Sourcepub fn with_stdlib_validation(self) -> Result<Self, String>
pub fn with_stdlib_validation(self) -> Result<Self, String>
Load validation module (chainable)
Sourcepub fn with_stdlib_datetime(self) -> Result<Self, String>
pub fn with_stdlib_datetime(self) -> Result<Self, String>
Load datetime module (chainable)
Sourcepub fn with_stdlib_testing(self) -> Result<Self, String>
pub fn with_stdlib_testing(self) -> Result<Self, String>
Load testing framework module (chainable)
Sourcepub fn with_stdlib_set(self) -> Result<Self, String>
pub fn with_stdlib_set(self) -> Result<Self, String>
Load set data structure module (chainable)
Sourcepub fn with_stdlib_queue(self) -> Result<Self, String>
pub fn with_stdlib_queue(self) -> Result<Self, String>
Load queue data structure module (chainable)
Sourcepub fn with_stdlib_stack(self) -> Result<Self, String>
pub fn with_stdlib_stack(self) -> Result<Self, String>
Load stack data structure module (chainable)
Sourcepub fn with_stdlib_heap(self) -> Result<Self, String>
pub fn with_stdlib_heap(self) -> Result<Self, String>
Load heap data structure module (chainable)
Sourcepub fn with_stdlib_sorting(self) -> Result<Self, String>
pub fn with_stdlib_sorting(self) -> Result<Self, String>
Load sorting algorithms module (chainable)
Sourcepub fn with_stdlib_json(self) -> Result<Self, String>
pub fn with_stdlib_json(self) -> Result<Self, String>
Load JSON processing module (chainable)
Sourcepub fn with_stdlib_csv(self) -> Result<Self, String>
pub fn with_stdlib_csv(self) -> Result<Self, String>
Load CSV processing module (chainable)
Sourcepub fn with_stdlib_functional(self) -> Result<Self, String>
pub fn with_stdlib_functional(self) -> Result<Self, String>
Load functional programming utilities module (chainable)
Sourcepub fn with_stdlib_cli_utils(self) -> Result<Self, String>
pub fn with_stdlib_cli_utils(self) -> Result<Self, String>
Load CLI utilities module (chainable)
Sourcepub fn with_stdlib_text_template(self) -> Result<Self, String>
pub fn with_stdlib_text_template(self) -> Result<Self, String>
Load text template engine module (chainable)
Sourcepub fn with_stdlib_regex_utils(self) -> Result<Self, String>
pub fn with_stdlib_regex_utils(self) -> Result<Self, String>
Load regex utilities module (chainable)
Sourcepub fn eval(&mut self, code: &str) -> Result<Value, String>
pub fn eval(&mut self, code: &str) -> Result<Value, String>
Evaluate Aether code and return the result
Sourcepub fn take_trace(&mut self) -> Vec<String>
pub fn take_trace(&mut self) -> Vec<String>
Drain the in-memory TRACE buffer.
This is designed for DSL-safe debugging: scripts call TRACE(...) to record
values, and the host application reads them out-of-band via this method.
Sourcepub fn clear_trace(&mut self)
pub fn clear_trace(&mut self)
Clear the TRACE buffer without returning it.
Sourcepub fn set_module_resolver(&mut self, resolver: Box<dyn ModuleResolver>)
pub fn set_module_resolver(&mut self, resolver: Box<dyn ModuleResolver>)
Configure the module resolver used for Import/Export.
By default (DSL embedding), the resolver is disabled for safety.
Sourcepub fn push_import_base(&mut self, module_id: String, base_dir: Option<PathBuf>)
pub fn push_import_base(&mut self, module_id: String, base_dir: Option<PathBuf>)
Push a base directory context for resolving relative imports.
This is typically used by a file-based runner (CLI) before calling eval().
Sourcepub fn pop_import_base(&mut self)
pub fn pop_import_base(&mut self)
Pop the most recent base directory context.
Sourcepub fn eval_file(&mut self, path: impl AsRef<Path>) -> Result<Value, String>
pub fn eval_file(&mut self, path: impl AsRef<Path>) -> Result<Value, String>
Evaluate an Aether script from a file path.
This is a convenience wrapper that:
- reads the file
- pushes an import base context (module_id = canonical path; base_dir = parent dir)
- evaluates the code
- pops the import base context
Note: this does not enable any module resolver. For DSL safety, module loading
remains disabled unless you explicitly call set_module_resolver(...).
Sourcepub fn set_global(&mut self, name: &str, value: Value)
pub fn set_global(&mut self, name: &str, value: Value)
Set a global variable from the host application without using eval().
This is useful when you already have Rust-side data and want to inject it
as Value into the script environment.
Sourcepub fn reset_env(&mut self)
pub fn reset_env(&mut self)
Reset the runtime environment (variables/functions) while keeping built-ins registered.
Note: this clears anything that was introduced via eval() (including stdlib code).
Sourcepub fn with_isolated_scope<R>(
&mut self,
f: impl FnOnce(&mut Aether) -> Result<R, String>,
) -> Result<R, String>
pub fn with_isolated_scope<R>( &mut self, f: impl FnOnce(&mut Aether) -> Result<R, String>, ) -> Result<R, String>
Run a closure inside an isolated child scope.
All variables/functions you inject or define inside the closure will be dropped when it returns, while the outer environment is preserved.
This is designed for the “DSL host” scenario: inject Rust data + load per-request Aether functions (e.g. from DB) + run the script, without cross-request pollution.
Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
获取缓存统计信息
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
清空缓存
Sourcepub fn set_optimization(
&mut self,
constant_folding: bool,
dead_code: bool,
tail_recursion: bool,
)
pub fn set_optimization( &mut self, constant_folding: bool, dead_code: bool, tail_recursion: bool, )
设置优化选项