pub struct StateGuard { /* private fields */ }Expand description
State 守卫,使用 RAII 模式自动管理 State 的设置和清理
当 StateGuard 被创建时,会自动设置当前线程的 State 上下文 当 StateGuard 被丢弃时(包括异常情况),会自动清理 State 上下文
§示例
use std::sync::Arc;
use moduforge_state::State;
use moduforge_rules_expression::functions::StateGuard;
// 创建 State
let state = Arc::new(create_test_state());
{
// 设置 State 上下文
let _guard = StateGuard::new(state);
// 在这个作用域内,自定义函数可以访问 State
// 即使发生 panic,State 也会被正确清理
} // 这里 StateGuard 被自动丢弃,State 上下文被清理Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StateGuard
impl RefUnwindSafe for StateGuard
impl Send for StateGuard
impl Sync for StateGuard
impl Unpin for StateGuard
impl UnwindSafe for StateGuard
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