pub struct EnginePool { /* private fields */ }Expand description
线程局部引擎池
§使用场景
- ✅ 单线程内需要多个引擎实例
- ✅ 避免频繁创建引擎的开销
- ✅ 需要环境隔离的高频调用
- ⚠️ 每个线程有独立的池(不跨线程共享)
§特点
- 线程局部:每个线程有独立的引擎池
- 自动管理:RAII模式,使用完自动归还
- 环境隔离:每次获取前清空变量
- AST缓存:每个引擎独立维护缓存
§示例
use aether::engine::EnginePool;
// 创建线程局部引擎池
let pool = EnginePool::new(4);
// 使用引擎
{
let mut engine = pool.acquire();
let result = engine.eval("Set X 10\n(X + 20)").unwrap();
println!("Result: {}", result);
} // engine 自动归还到池中
// 多次使用(复用引擎实例)
for i in 0..100 {
let mut engine = pool.acquire();
let code = format!("Set X {}\n(X * 2)", i);
engine.eval(&code).unwrap();
}§与 GlobalEngine 对比
- GlobalEngine: 单个引擎实例,适合简单场景
- EnginePool: 多个引擎实例,避免频繁创建开销
如果你只需要一个引擎实例,使用 GlobalEngine 更简单。
Implementations§
Source§impl EnginePool
impl EnginePool
Auto Trait Implementations§
impl Freeze for EnginePool
impl !RefUnwindSafe for EnginePool
impl !Send for EnginePool
impl !Sync for EnginePool
impl Unpin for EnginePool
impl !UnwindSafe for EnginePool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more