aether/api/
stdlib.rs

1use super::Aether;
2use crate::stdlib;
3
4impl Aether {
5    /// 加载特定的标准库模块
6    ///
7    /// 可用模块:"string_utils"、"array_utils"、"validation"、"datetime"、"testing"
8    pub fn load_stdlib_module(&mut self, module_name: &str) -> Result<(), String> {
9        if let Some(code) = stdlib::get_module(module_name) {
10            self.eval(code)?;
11            Ok(())
12        } else {
13            Err(format!("Unknown stdlib module: {}", module_name))
14        }
15    }
16
17    /// 加载所有标准库模块
18    pub fn load_all_stdlib(&mut self) -> Result<(), String> {
19        stdlib::preload_stdlib(self)
20    }
21
22    // ============================================================
23    // 可链式调用的 stdlib 模块加载方法
24    // ============================================================
25
26    /// 加载字符串工具模块(可链式调用)
27    pub fn with_stdlib_string_utils(mut self) -> Result<Self, String> {
28        if let Some(code) = stdlib::get_module("string_utils") {
29            self.eval(code)?;
30        }
31        Ok(self)
32    }
33
34    /// 加载数组工具模块(可链式调用)
35    pub fn with_stdlib_array_utils(mut self) -> Result<Self, String> {
36        if let Some(code) = stdlib::get_module("array_utils") {
37            self.eval(code)?;
38        }
39        Ok(self)
40    }
41
42    /// 加载验证模块(可链式调用)
43    pub fn with_stdlib_validation(mut self) -> Result<Self, String> {
44        if let Some(code) = stdlib::get_module("validation") {
45            self.eval(code)?;
46        }
47        Ok(self)
48    }
49
50    /// 加载日期时间模块(可链式调用)
51    pub fn with_stdlib_datetime(mut self) -> Result<Self, String> {
52        if let Some(code) = stdlib::get_module("datetime") {
53            self.eval(code)?;
54        }
55        Ok(self)
56    }
57
58    /// 加载测试框架模块(可链式调用)
59    pub fn with_stdlib_testing(mut self) -> Result<Self, String> {
60        if let Some(code) = stdlib::get_module("testing") {
61            self.eval(code)?;
62        }
63        Ok(self)
64    }
65
66    /// 加载集合数据结构模块(可链式调用)
67    pub fn with_stdlib_set(mut self) -> Result<Self, String> {
68        if let Some(code) = stdlib::get_module("set") {
69            self.eval(code)?;
70        }
71        Ok(self)
72    }
73
74    /// 加载队列数据结构模块(可链式调用)
75    pub fn with_stdlib_queue(mut self) -> Result<Self, String> {
76        if let Some(code) = stdlib::get_module("queue") {
77            self.eval(code)?;
78        }
79        Ok(self)
80    }
81
82    /// 加载栈数据结构模块(可链式调用)
83    pub fn with_stdlib_stack(mut self) -> Result<Self, String> {
84        if let Some(code) = stdlib::get_module("stack") {
85            self.eval(code)?;
86        }
87        Ok(self)
88    }
89
90    /// 加载堆数据结构模块(可链式调用)
91    pub fn with_stdlib_heap(mut self) -> Result<Self, String> {
92        if let Some(code) = stdlib::get_module("heap") {
93            self.eval(code)?;
94        }
95        Ok(self)
96    }
97
98    /// 加载排序算法模块(可链式调用)
99    pub fn with_stdlib_sorting(mut self) -> Result<Self, String> {
100        if let Some(code) = stdlib::get_module("sorting") {
101            self.eval(code)?;
102        }
103        Ok(self)
104    }
105
106    /// 加载 JSON 处理模块(可链式调用)
107    pub fn with_stdlib_json(mut self) -> Result<Self, String> {
108        if let Some(code) = stdlib::get_module("json") {
109            self.eval(code)?;
110        }
111        Ok(self)
112    }
113
114    /// 加载 CSV 处理模块(可链式调用)
115    pub fn with_stdlib_csv(mut self) -> Result<Self, String> {
116        if let Some(code) = stdlib::get_module("csv") {
117            self.eval(code)?;
118        }
119        Ok(self)
120    }
121
122    /// 加载函数式编程工具模块(可链式调用)
123    pub fn with_stdlib_functional(mut self) -> Result<Self, String> {
124        if let Some(code) = stdlib::get_module("functional") {
125            self.eval(code)?;
126        }
127        Ok(self)
128    }
129
130    /// 加载 CLI 工具模块(可链式调用)
131    pub fn with_stdlib_cli_utils(mut self) -> Result<Self, String> {
132        if let Some(code) = stdlib::get_module("cli_utils") {
133            self.eval(code)?;
134        }
135        Ok(self)
136    }
137
138    /// 加载文本模板引擎模块(可链式调用)
139    pub fn with_stdlib_text_template(mut self) -> Result<Self, String> {
140        if let Some(code) = stdlib::get_module("text_template") {
141            self.eval(code)?;
142        }
143        Ok(self)
144    }
145
146    /// 加载正则表达式工具模块(可链式调用)
147    pub fn with_stdlib_regex_utils(mut self) -> Result<Self, String> {
148        if let Some(code) = stdlib::get_module("regex_utils") {
149            self.eval(code)?;
150        }
151        Ok(self)
152    }
153}