Struct ForgeAsyncRuntime

Source
pub struct ForgeAsyncRuntime { /* private fields */ }
Expand description

异步编�器运行时

提供异步操作支持的编辑器运行时,包含:

  • 基础编辑器功能(通过 ForgeRuntime)
  • 异步流引擎(用于处理复杂的异步操作流)

配置通过基础 ForgeRuntime 访问,避免重复持有

Implementations§

Source§

impl ForgeAsyncRuntime

Source

pub async fn create(options: RuntimeOptions) -> ForgeResult<Self>

创建新的编辑器实例

此方法会自动从以下位置加载XML schema配置:

  1. 优先使用 config.extension.xml_schema_paths 中配置的路径
  2. 如果没有配置,则尝试加载默认的 schema/main.xml
  3. 如果都没有,则使用默认配置
§参数
  • options - 编辑器配置选项
§返回值
  • ForgeResult<Self> - 异步编辑器实例或错误
Source

pub async fn from_xml_schema_path( xml_schema_path: &str, options: Option<RuntimeOptions>, config: Option<ForgeConfig>, ) -> ForgeResult<Self>

从指定路径的XML schema文件创建异步编辑器实例

§参数
  • xml_schema_path - XML schema文件路径
  • options - 可选的RuntimeOptions配置
  • config - 可选的ForgeConfig配置
§返回值
  • ForgeResult<Self> - 异步编辑器实例或错误
§示例
use mf_core::ForgeAsyncRuntime;

// 从指定路径加载schema
let runtime = ForgeAsyncRuntime::from_xml_schema_path(
    "./schemas/document.xml",
    None,
    None
).await?;
Source

pub async fn from_xml_schemas( xml_schema_paths: &[&str], options: Option<RuntimeOptions>, config: Option<ForgeConfig>, ) -> ForgeResult<Self>

从多个XML schema文件创建异步编辑器实例

§参数
  • xml_schema_paths - XML schema文件路径列表
  • options - 可选的RuntimeOptions配置
  • config - 可选的ForgeConfig配置
§返回值
  • ForgeResult<Self> - 异步编辑器实例或错误
Source

pub async fn from_xml_content( xml_content: &str, options: Option<RuntimeOptions>, config: Option<ForgeConfig>, ) -> ForgeResult<Self>

从XML内容字符串创建异步编辑器实例

§参数
  • xml_content - XML schema内容
  • options - 可选的RuntimeOptions配置
  • config - 可选的ForgeConfig配置
§返回值
  • ForgeResult<Self> - 异步编辑器实例或错误
Source

pub async fn create_with_config( options: RuntimeOptions, config: ForgeConfig, ) -> ForgeResult<Self>

使用指定配置创建异步编辑器实例

此方法会自动从以下位置加载XML schema配置:

  1. 优先使用 config.extension.xml_schema_paths 中配置的路径
  2. 如果没有配置,则尝试加载默认的 schema/main.xml
  3. 如果都没有,则使用默认配置
§参数
  • options - 编辑器配置选项
  • config - 编辑器配置
§返回值
  • ForgeResult<Self> - 异步编辑器实例或错误
Source

pub fn set_performance_config(&mut self, perf_config: PerformanceConfig)

设置性能监控配置

Source

pub fn get_config(&self) -> &ForgeConfig

获取当前配置

Source

pub fn update_config(&mut self, config: ForgeConfig)

更新配置

Source

pub async fn command(&mut self, command: Arc<dyn Command>) -> ForgeResult<()>

Source

pub async fn command_with_meta( &mut self, command: Arc<dyn Command>, description: String, meta: Value, ) -> ForgeResult<()>

执行命令并生成相应的事务

此方法封装了命令到事务的转换过程,并使用高性能的dispatch_flow来处理生成的事务。 适用于需要执行编辑器命令而不直接构建事务的场景。

§参数
  • command - 要执行的命令
§返回值
  • EditorResult<()> - 命令执行结果
Source

pub async fn dispatch_flow( &mut self, transaction: Transaction, ) -> ForgeResult<()>

Source

pub async fn dispatch_flow_with_meta( &mut self, transaction: Transaction, description: String, meta: Value, ) -> ForgeResult<()>

高性能事务处理方法,使用FlowEngine处理事务

与标准的dispatch方法相比,此方法具有以下优势:

  1. 利用FlowEngine提供的并行处理能力
  2. 通过异步流水线处理提高性能
  3. 减少阻塞操作,提升UI响应性
  4. 更好地处理大型文档的编辑操作
§参数
  • transaction - 要处理的事务对象
§返回值
  • EditorResult<()> - 处理结果,成功返回Ok(()), 失败返回错误
Source

pub async fn run_before_middleware( &mut self, transaction: &mut Transaction, ) -> ForgeResult<()>

Source

pub async fn run_after_middleware( &mut self, state: &mut Option<Arc<State>>, transactions: &mut Vec<Transaction>, ) -> ForgeResult<()>

Source

pub async fn shutdown(&mut self) -> ForgeResult<()>

优雅关闭异步运行时

这个方法会:

  1. 停止接受新任务
  2. 等待所有正在处理的任务完成
  3. 关闭底层的异步处理器
  4. 清理所有资源

Methods from Deref<Target = ForgeRuntime>§

Source

pub async fn destroy(&mut self) -> ForgeResult<()>

销毁编辑器实例

Source

pub async fn emit_event(&mut self, event: Event) -> ForgeResult<()>

Source

pub async fn run_before_middleware( &mut self, transaction: &mut Transaction, ) -> ForgeResult<()>

Source

pub async fn run_after_middleware( &mut self, state: &mut Option<Arc<State>>, transactions: &mut Vec<Transaction>, ) -> ForgeResult<()>

Source

pub async fn command(&mut self, command: Arc<dyn Command>) -> ForgeResult<()>

Source

pub async fn command_with_meta( &mut self, command: Arc<dyn Command>, description: String, meta: Value, ) -> ForgeResult<()>

Source

pub async fn dispatch(&mut self, transaction: Transaction) -> ForgeResult<()>

处理编辑器事务的核心方法

§参数
  • transaction - 要处理的事务对象
§返回值
  • EditorResult<()> - 处理结果,成功返回 Ok(()), 失败返回错误
Source

pub async fn dispatch_with_meta( &mut self, transaction: Transaction, description: String, meta: Value, ) -> ForgeResult<()>

更新编辑器状态并记录到历史记录 包含描述和元信息

Source

pub async fn update_state(&mut self, state: Arc<State>) -> ForgeResult<()>

更新编辑器状态并记录到历史记录 不包含描述和元信息

Source

pub async fn update_state_with_meta( &mut self, state: Arc<State>, description: String, meta: Value, ) -> ForgeResult<()>

更新编辑器状态并记录到历史记录 包含描述和元信息

Source

pub async fn register_plugin(&mut self) -> ForgeResult<()>

Source

pub async fn unregister_plugin(&mut self, plugin_key: String) -> ForgeResult<()>

Source

pub fn doc(&self) -> Arc<NodePool>

共享的基础实现方法

Source

pub fn get_options(&self) -> &RuntimeOptions

Source

pub fn get_config(&self) -> &ForgeConfig

获取当前配置

Source

pub fn update_config(&mut self, config: ForgeConfig)

更新配置

Source

pub fn get_state(&self) -> &Arc<State>

Source

pub fn get_schema(&self) -> Arc<Schema>

Source

pub fn get_event_bus(&self) -> &EventBus<Event>

Source

pub fn get_tr(&self) -> Transaction

Source

pub fn undo(&mut self)

Source

pub fn redo(&mut self)

Source

pub fn jump(&mut self, n: isize)

Source

pub fn get_history_manager(&self) -> &HistoryManager<HistoryEntryWithMeta>

Trait Implementations§

Source§

impl Deref for ForgeAsyncRuntime

Source§

type Target = ForgeRuntime

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for ForgeAsyncRuntime

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Send for ForgeAsyncRuntime

Source§

impl Sync for ForgeAsyncRuntime

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more