Aether

Struct Aether 

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

Main Aether engine struct

Implementations§

Source§

impl Aether

Source

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.

Source

pub fn with_permissions(permissions: IOPermissions) -> Self

Create a new Aether engine with custom IO permissions

Source

pub fn with_all_permissions() -> Self

Create a new Aether engine with all IO permissions enabled

Source

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).

Source

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”

Source

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

Load all standard library modules

Source

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

Create a new Aether engine with execution limits

Source

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

Set execution limits

Source

pub fn limits(&self) -> &ExecutionLimits

Get current execution limits

Source

pub fn with_stdlib_string_utils(self) -> Result<Self, String>

Load string utilities module (chainable)

Source

pub fn with_stdlib_array_utils(self) -> Result<Self, String>

Load array utilities module (chainable)

Source

pub fn with_stdlib_validation(self) -> Result<Self, String>

Load validation module (chainable)

Source

pub fn with_stdlib_datetime(self) -> Result<Self, String>

Load datetime module (chainable)

Source

pub fn with_stdlib_testing(self) -> Result<Self, String>

Load testing framework module (chainable)

Source

pub fn with_stdlib_set(self) -> Result<Self, String>

Load set data structure module (chainable)

Source

pub fn with_stdlib_queue(self) -> Result<Self, String>

Load queue data structure module (chainable)

Source

pub fn with_stdlib_stack(self) -> Result<Self, String>

Load stack data structure module (chainable)

Source

pub fn with_stdlib_heap(self) -> Result<Self, String>

Load heap data structure module (chainable)

Source

pub fn with_stdlib_sorting(self) -> Result<Self, String>

Load sorting algorithms module (chainable)

Source

pub fn with_stdlib_json(self) -> Result<Self, String>

Load JSON processing module (chainable)

Source

pub fn with_stdlib_csv(self) -> Result<Self, String>

Load CSV processing module (chainable)

Source

pub fn with_stdlib_functional(self) -> Result<Self, String>

Load functional programming utilities module (chainable)

Source

pub fn with_stdlib_cli_utils(self) -> Result<Self, String>

Load CLI utilities module (chainable)

Source

pub fn with_stdlib_text_template(self) -> Result<Self, String>

Load text template engine module (chainable)

Source

pub fn with_stdlib_regex_utils(self) -> Result<Self, String>

Load regex utilities module (chainable)

Source

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

Evaluate Aether code and return the result

Source

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

Evaluate Aether code and return a structured error report on failure.

This is intended for integrations that need machine-readable diagnostics.

Source

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.

Source

pub fn clear_trace(&mut self)

Clear the TRACE buffer without returning it.

Source

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

Get all structured trace entries (Stage 3.2)

Returns a vector of structured trace entries with levels, categories, timestamps, etc.

Source

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

Filter trace entries by level (Stage 3.2)

§Example
let error_traces = engine.trace_by_level(crate::runtime::TraceLevel::Error);
Source

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

Filter trace entries by category (Stage 3.2)

§Example
let api_traces = engine.trace_by_category("api_call");
Source

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

Filter trace entries by label (Stage 3.2)

§Example
let slow_traces = engine.trace_by_label("slow_request");
Source

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

Apply complex filter to trace entries (Stage 3.2)

§Example
use crate::runtime::{TraceFilter, TraceLevel};
use std::time::Instant;

let filter = TraceFilter::new()
    .with_min_level(TraceLevel::Warn)
    .with_category("api".to_string());
let filtered = engine.trace_filter(&filter);
Source

pub fn trace_stats(&self) -> TraceStats

Get trace statistics (Stage 3.2)

Returns statistics about trace entries, including counts by level and category.

Source

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

Set TRACE buffer size (Stage 3.2)

Note: This method is a placeholder for future implementation. Currently, the buffer size is fixed at 1024 entries.

Source

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.

Source

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().

Source

pub fn pop_import_base(&mut self)

Pop the most recent base directory context.

Source

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(...).

Source

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

Evaluate an Aether script from a file path, returning a structured error report on failure.

Source

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.

Source

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).

Source

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.

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, )

设置优化选项

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 Unpin for Aether

§

impl !UnwindSafe 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.