pub struct Isolate<'arena> { /* private fields */ }Expand description
Isolate 是一个组件,用于封装一个隔离的环境,用于执行表达式。
重新运行 Isolate 允许通过 arena 分配器进行高效的内存重用。 arena 分配器通过重用内存块来优化内存管理,从而在 Isolate 被多次重用时提高性能和资源利用率。
🆕 现在支持扩展机制和State集成
Implementations§
Source§impl<'a> Isolate<'a>
impl<'a> Isolate<'a>
pub fn new() -> Self
pub fn with_environment(variable: Variable) -> Self
pub fn set_environment(&mut self, variable: Variable)
pub fn update_environment<F>(&mut self, updater: F)
pub fn set_reference(&mut self, reference: &'a str) -> Result<(), IsolateError>
pub fn get_reference(&self, reference: &str) -> Option<Variable>
pub fn clear_references(&mut self)
pub fn compile_standard( &mut self, source: &'a str, ) -> Result<Expression<Standard>, IsolateError>
pub fn run_standard( &mut self, source: &'a str, ) -> Result<Variable, IsolateError>
Sourcepub fn run_standard_with_state(
&mut self,
source: &'a str,
state: Arc<State>,
) -> Result<Variable, IsolateError>
pub fn run_standard_with_state( &mut self, source: &'a str, state: Arc<State>, ) -> Result<Variable, IsolateError>
运行标准表达式,并传入State供自定义函数使用
使用 RAII 模式确保 State 的异常安全管理
pub fn compile_unary( &mut self, source: &'a str, ) -> Result<Expression<Unary>, IsolateError>
pub fn run_unary(&mut self, source: &'a str) -> Result<bool, IsolateError>
Sourcepub fn run_unary_with_state(
&mut self,
source: &'a str,
state: Arc<State>,
) -> Result<bool, IsolateError>
pub fn run_unary_with_state( &mut self, source: &'a str, state: Arc<State>, ) -> Result<bool, IsolateError>
运行一元表达式,并传入State供自定义函数使用
使用 RAII 模式确保 State 的异常安全管理
Sourcepub fn register_custom_function<F>(
name: String,
params: Vec<VariableType>,
return_type: VariableType,
executor: F,
) -> Result<(), String>
pub fn register_custom_function<F>( name: String, params: Vec<VariableType>, return_type: VariableType, executor: F, ) -> Result<(), String>
注册自定义函数(可在表达式中直接调用)
Sourcepub fn list_custom_functions() -> Vec<String>
pub fn list_custom_functions() -> Vec<String>
列出所有已注册的自定义函数
Sourcepub fn clear_custom_functions()
pub fn clear_custom_functions()
清空所有自定义函数
Trait Implementations§
Auto Trait Implementations§
impl<'arena> Freeze for Isolate<'arena>
impl<'arena> !RefUnwindSafe for Isolate<'arena>
impl<'arena> !Send for Isolate<'arena>
impl<'arena> !Sync for Isolate<'arena>
impl<'arena> Unpin for Isolate<'arena>
impl<'arena> !UnwindSafe for Isolate<'arena>
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more