RuntimeTrait

Trait RuntimeTrait 

Source
pub trait RuntimeTrait: Send {
Show 15 methods // Required methods fn dispatch<'life0, 'async_trait>( &'life0 mut self, transaction: Transaction, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn dispatch_with_meta<'life0, 'async_trait>( &'life0 mut self, transaction: Transaction, description: String, meta: Value, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn command<'life0, 'async_trait>( &'life0 mut self, command: Arc<dyn Command>, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn command_with_meta<'life0, 'async_trait>( &'life0 mut self, command: Arc<dyn Command>, description: String, meta: Value, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_state<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ForgeResult<Arc<State>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_tr<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ForgeResult<Transaction>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_schema<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ForgeResult<Arc<Schema>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn undo<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn redo<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn jump<'life0, 'async_trait>( &'life0 mut self, steps: isize, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_config(&self) -> &ForgeConfig; fn update_config(&mut self, config: ForgeConfig); fn get_options(&self) -> &RuntimeOptions; fn destroy<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided method fn doc<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ForgeResult<Arc<NodePool>>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait { ... }
}
Expand description

运行时统一接口

定义了所有运行时实现必须提供的核心功能。 所有方法都是异步的,以支持不同的执行模型。

§设计原则

  1. 接口最小化: 只包含核心必需方法
  2. 异步优先: 所有方法异步,兼容三种运行时
  3. 错误统一: 使用 ForgeResult 统一错误处理
  4. 状态不可变: 返回 Arc 避免克隆

§使用示例

use mf_core::{ForgeRuntime, RuntimeTrait};

async fn process_with_runtime(runtime: &mut dyn RuntimeTrait) -> ForgeResult<()> {
    let state = runtime.get_state().await?;
    let mut tr = runtime.get_tr().await?;

    // ... 修改事务 ...

    runtime.dispatch(tr).await?;
    Ok(())
}

Required Methods§

Source

fn dispatch<'life0, 'async_trait>( &'life0 mut self, transaction: Transaction, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

分发事务到运行时处理

这是运行时的核心方法,负责:

  1. 执行前置中间件
  2. 应用事务到状态
  3. 触发插件的 append_transaction
  4. 执行后置中间件
  5. 更新状态和历史
  6. 广播事件
§参数
  • transaction - 要处理的事务
§返回值
  • ForgeResult<()> - 处理结果
Source

fn dispatch_with_meta<'life0, 'async_trait>( &'life0 mut self, transaction: Transaction, description: String, meta: Value, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

分发事务(包含元信息)

与 dispatch 相同,但可以附加描述和元数据,用于:

  • 历史记录的可读性
  • 审计日志
  • 撤销/重做时的显示
§参数
  • transaction - 要处理的事务
  • description - 事务描述(用于历史记录)
  • meta - 元数据(JSON格式)
Source

fn command<'life0, 'async_trait>( &'life0 mut self, command: Arc<dyn Command>, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

执行命令

命令是对事务的高级封装,提供:

  • 类型安全的操作
  • 可复用的业务逻辑
  • 更好的测试性
§参数
  • command - 要执行的命令
Source

fn command_with_meta<'life0, 'async_trait>( &'life0 mut self, command: Arc<dyn Command>, description: String, meta: Value, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

执行命令(包含元信息)

Source

fn get_state<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ForgeResult<Arc<State>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

获取当前状态

返回不可变状态引用,避免克隆开销。 状态是快照,读取时不会被其他操作修改。

Source

fn get_tr<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ForgeResult<Transaction>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

获取新事务

基于当前状态创建新事务,用于构建编辑操作。

Source

fn get_schema<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ForgeResult<Arc<Schema>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

获取Schema

返回文档结构定义

Source

fn undo<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

撤销操作

回退到上一个历史状态

Source

fn redo<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

重做操作

前进到下一个历史状态

Source

fn jump<'life0, 'async_trait>( &'life0 mut self, steps: isize, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

跳转到指定历史位置

§参数
  • steps - 跳转步数(正数前进,负数后退)
Source

fn get_config(&self) -> &ForgeConfig

获取运行时配置

Source

fn update_config(&mut self, config: ForgeConfig)

更新运行时配置

Source

fn get_options(&self) -> &RuntimeOptions

获取运行时选项

Source

fn destroy<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

销毁运行时

清理所有资源,包括:

  • 停止事件循环
  • 关闭Actor系统(如果适用)
  • 释放异步资源(如果适用)

Provided Methods§

Source

fn doc<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ForgeResult<Arc<NodePool>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

获取文档

快捷方法,等同于 get_state().await?.doc()

Trait Implementations§

Source§

impl RuntimeExt for Box<dyn RuntimeTrait>

Source§

fn runtime_type_name(&self) -> &'static str

获取运行时类型描述

Implementors§