Skip to main content

SecretaryContext

Struct SecretaryContext 

Source
pub struct SecretaryContext<State> { /* private fields */ }
Expand description

秘书上下文

在秘书处理过程中传递状态和共享资源。

§类型参数

  • State: 用户定义的状态类型

§示例

struct MyState {
    counter: u32,
}

let mut ctx = SecretaryContext::new(MyState { counter: 0 });
ctx.state_mut().counter += 1;
ctx.set_metadata("key", "value");

Implementations§

Source§

impl<State> SecretaryContext<State>

Source

pub fn new(state: State) -> Self

创建新的上下文

Source

pub fn state(&self) -> &State

获取状态引用

Source

pub fn state_mut(&mut self) -> &mut State

获取状态可变引用

Source

pub fn set_state(&mut self, state: State)

替换状态

Source

pub fn set_metadata<T: Any + Send + Sync>( &mut self, key: impl Into<String>, value: T, )

设置元数据

Source

pub fn get_metadata<T: Any + Send + Sync>(&self, key: &str) -> Option<&T>

获取元数据

Source

pub fn remove_metadata(&mut self, key: &str) -> bool

移除元数据

Source

pub fn register_resource<T: Any + Send + Sync>( &mut self, key: impl Into<String>, resource: Arc<T>, )

注册共享资源

Source

pub fn get_resource<T: Any + Send + Sync>(&self, key: &str) -> Option<Arc<T>>

获取共享资源

Source

pub fn has_resource(&self, key: &str) -> bool

检查资源是否存在

Auto Trait Implementations§

§

impl<State> Freeze for SecretaryContext<State>
where State: Freeze,

§

impl<State> !RefUnwindSafe for SecretaryContext<State>

§

impl<State> Send for SecretaryContext<State>
where State: Send,

§

impl<State> Sync for SecretaryContext<State>
where State: Sync,

§

impl<State> Unpin for SecretaryContext<State>
where State: Unpin,

§

impl<State> UnsafeUnpin for SecretaryContext<State>
where State: UnsafeUnpin,

§

impl<State> !UnwindSafe for SecretaryContext<State>

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.