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
运行时统一接口
定义了所有运行时实现必须提供的核心功能。 所有方法都是异步的,以支持不同的执行模型。
§设计原则
- 接口最小化: 只包含核心必需方法
- 异步优先: 所有方法异步,兼容三种运行时
- 错误统一: 使用 ForgeResult 统一错误处理
- 状态不可变: 返回 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§
Sourcefn 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<'life0, 'async_trait>(
&'life0 mut self,
transaction: Transaction,
) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sourcefn 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 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格式)
Sourcefn 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<'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,
Sourcefn 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 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,
执行命令(包含元信息)
Sourcefn 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_state<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ForgeResult<Arc<State>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
获取当前状态
返回不可变状态引用,避免克隆开销。 状态是快照,读取时不会被其他操作修改。
Sourcefn 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_tr<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ForgeResult<Transaction>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
获取新事务
基于当前状态创建新事务,用于构建编辑操作。
Sourcefn 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 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
返回文档结构定义
Sourcefn undo<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = ForgeResult<()>> + 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,
撤销操作
回退到上一个历史状态
Sourcefn redo<'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,
重做操作
前进到下一个历史状态
Sourcefn 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 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,
Sourcefn get_config(&self) -> &ForgeConfig
fn get_config(&self) -> &ForgeConfig
获取运行时配置
Sourcefn update_config(&mut self, config: ForgeConfig)
fn update_config(&mut self, config: ForgeConfig)
更新运行时配置
Sourcefn get_options(&self) -> &RuntimeOptions
fn get_options(&self) -> &RuntimeOptions
获取运行时选项
Provided Methods§
Trait Implementations§
Source§impl RuntimeExt for Box<dyn RuntimeTrait>
impl RuntimeExt for Box<dyn RuntimeTrait>
Source§fn runtime_type_name(&self) -> &'static str
fn runtime_type_name(&self) -> &'static str
获取运行时类型描述