Module builder

Module builder 

Source
Expand description

统一运行时构建器

提供统一、流畅的运行时创建接口,支持:

  1. 自动检测系统资源并选择最优运行时
  2. 手动指定运行时类型
  3. 使用配置文件创建运行时
  4. 链式配置构建

§设计原则

  • 简单优先:最常见的用例应该最简单
  • 渐进式配置:从简单到复杂,逐步添加配置
  • 类型安全:编译期捕获配置错误
  • 统一接口:所有创建方式返回统一的运行时类型

§使用示例

§1. 最简单的方式(推荐)

use mf_core::ForgeRuntimeBuilder;

// 自动检测系统资源,选择最优运行时和配置
let runtime = ForgeRuntimeBuilder::new().build().await?;

§2. 指定运行时类型

use mf_core::{ForgeRuntimeBuilder, RuntimeType};

// 明确使用 Actor 运行时
let runtime = ForgeRuntimeBuilder::new()
    .runtime_type(RuntimeType::Actor)
    .build()
    .await?;

§3. 链式配置

use mf_core::{ForgeRuntimeBuilder, RuntimeType, Extensions};

let runtime = ForgeRuntimeBuilder::new()
    .runtime_type(RuntimeType::Async)
    .max_concurrent_tasks(20)
    .queue_size(5000)
    .enable_monitoring(true)
    .history_limit(1000)
    .extension(my_extension)
    .build()
    .await?;

§4. 从配置文件

use mf_core::ForgeRuntimeBuilder;

let runtime = ForgeRuntimeBuilder::from_config_file("config.toml")
    .await?
    .build()
    .await?;

§5. 从 XML Schema

use mf_core::ForgeRuntimeBuilder;

let runtime = ForgeRuntimeBuilder::new()
    .schema_path("schema/document.xml")
    .build()
    .await?;

Structs§

ForgeRuntimeBuilder
统一运行时构建器

Enums§

AnyRuntime
统一的运行时枚举