ForgeRuntimeBuilder

Struct ForgeRuntimeBuilder 

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

统一运行时构建器

提供流畅的链式 API 来配置和创建运行时。

§设计特点

  1. 自动推断:未指定的配置项会根据系统资源自动优化
  2. 类型安全:配置错误在编译期捕获
  3. 灵活组合:可以混合使用不同的配置方式
  4. 统一返回:始终返回 AnyRuntime 枚举,避免 trait object 开销

§示例

// 最简单的用法
let runtime = ForgeRuntimeBuilder::new().build().await?;

// 完全自定义
let runtime = ForgeRuntimeBuilder::new()
    .runtime_type(RuntimeType::Actor)
    .environment(Environment::Production)
    .max_concurrent_tasks(20)
    .build()
    .await?;

Implementations§

Source§

impl ForgeRuntimeBuilder

Source

pub fn new() -> Self

创建新的构建器实例

§示例
let builder = ForgeRuntimeBuilder::new();
Source

pub fn runtime_type(self, runtime_type: RuntimeType) -> Self

设置运行时类型

如果不设置,将根据系统资源自动选择。

§示例
let builder = ForgeRuntimeBuilder::new()
    .runtime_type(RuntimeType::Actor);
Source

pub fn environment(self, environment: Environment) -> Self

设置运行环境

不同环境有不同的默认配置。

§示例
let builder = ForgeRuntimeBuilder::new()
    .environment(Environment::Production);
Source

pub fn content(self, content: Content) -> Self

设置初始内容

§示例
let builder = ForgeRuntimeBuilder::new()
    .content(Content::Json(json_data));
Source

pub fn extension(self, extension: Extensions) -> Self

添加扩展

§示例
let builder = ForgeRuntimeBuilder::new()
    .extension(Extensions::N(my_node));
Source

pub fn extensions(self, extensions: Vec<Extensions>) -> Self

批量添加扩展

§示例
let builder = ForgeRuntimeBuilder::new()
    .extensions(vec![ext1, ext2, ext3]);
Source

pub fn schema_path(self, path: impl Into<String>) -> Self

从 XML Schema 文件加载扩展

§示例
let builder = ForgeRuntimeBuilder::new()
    .schema_path("schema/document.xml");
Source

pub fn schema_paths(self, paths: Vec<String>) -> Self

从多个 XML Schema 文件加载扩展

§示例
let builder = ForgeRuntimeBuilder::new()
    .schema_paths(vec!["schema/doc.xml", "schema/ui.xml"]);
Source

pub fn max_concurrent_tasks(self, count: usize) -> Self

设置最大并发任务数

如果不设置,将根据 CPU 核心数自动计算。

§示例
let builder = ForgeRuntimeBuilder::new()
    .max_concurrent_tasks(20);
Source

pub fn queue_size(self, size: usize) -> Self

设置任务队列大小

如果不设置,将根据可用内存自动计算。

§示例
let builder = ForgeRuntimeBuilder::new()
    .queue_size(5000);
Source

pub fn enable_monitoring(self, enable: bool) -> Self

启用或禁用性能监控

§示例
let builder = ForgeRuntimeBuilder::new()
    .enable_monitoring(true);
Source

pub fn middleware_timeout_ms(self, timeout: u64) -> Self

设置中间件超时时间(毫秒)

§示例
let builder = ForgeRuntimeBuilder::new()
    .middleware_timeout_ms(1000);
Source

pub fn history_limit(self, limit: usize) -> Self

设置历史记录限制

§示例
let builder = ForgeRuntimeBuilder::new()
    .history_limit(1000);
Source

pub fn event_handler( self, handler: Arc<dyn EventHandler<Event> + Send + Sync>, ) -> Self

添加事件处理器

§示例
let builder = ForgeRuntimeBuilder::new()
    .event_handler(my_handler);
Source

pub fn with_config(self, config: ForgeConfig) -> Self

使用完整的 ForgeConfig

这会覆盖之前设置的所有配置项。

§示例
let config = ForgeConfig::for_environment(Environment::Production);
let builder = ForgeRuntimeBuilder::new()
    .with_config(config);
Source

pub async fn from_config_file(path: &str) -> ForgeResult<Self>

从 JSON 配置文件加载

§示例
let builder = ForgeRuntimeBuilder::from_config_file("config.json").await?;
Source

pub async fn build(self) -> ForgeResult<AnyRuntime>

构建运行时实例

这是最终的构建方法,会:

  1. 合并所有配置
  2. 检测系统资源(如果需要)
  3. 创建运行时实例
§返回值
  • ForgeResult<AnyRuntime> - 运行时实例或错误
§示例
let runtime = ForgeRuntimeBuilder::new()
    .runtime_type(RuntimeType::Async)
    .max_concurrent_tasks(20)
    .build()
    .await?;

Trait Implementations§

Source§

impl Default for ForgeRuntimeBuilder

Source§

fn default() -> ForgeRuntimeBuilder

Returns the “default value” for a type. Read more

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> Message for T
where T: Any + Send + 'static,

Source§

fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>

Convert a BoxedMessage to this concrete type
Source§

fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>

Convert this message to a BoxedMessage
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<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
Source§

impl<T> State for T
where T: Any + Send + 'static,