pub struct ForgeRuntimeBuilder { /* private fields */ }Expand description
统一运行时构建器
提供流畅的链式 API 来配置和创建运行时。
§设计特点
- 自动推断:未指定的配置项会根据系统资源自动优化
- 类型安全:配置错误在编译期捕获
- 灵活组合:可以混合使用不同的配置方式
- 统一返回:始终返回
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
impl ForgeRuntimeBuilder
Sourcepub fn runtime_type(self, runtime_type: RuntimeType) -> Self
pub fn runtime_type(self, runtime_type: RuntimeType) -> Self
设置运行时类型
如果不设置,将根据系统资源自动选择。
§示例
let builder = ForgeRuntimeBuilder::new()
.runtime_type(RuntimeType::Actor);Sourcepub fn environment(self, environment: Environment) -> Self
pub fn environment(self, environment: Environment) -> Self
设置运行环境
不同环境有不同的默认配置。
§示例
let builder = ForgeRuntimeBuilder::new()
.environment(Environment::Production);Sourcepub fn extension(self, extension: Extensions) -> Self
pub fn extension(self, extension: Extensions) -> Self
Sourcepub fn extensions(self, extensions: Vec<Extensions>) -> Self
pub fn extensions(self, extensions: Vec<Extensions>) -> Self
Sourcepub fn schema_path(self, path: impl Into<String>) -> Self
pub fn schema_path(self, path: impl Into<String>) -> Self
从 XML Schema 文件加载扩展
§示例
let builder = ForgeRuntimeBuilder::new()
.schema_path("schema/document.xml");Sourcepub fn schema_paths(self, paths: Vec<String>) -> Self
pub fn schema_paths(self, paths: Vec<String>) -> Self
从多个 XML Schema 文件加载扩展
§示例
let builder = ForgeRuntimeBuilder::new()
.schema_paths(vec!["schema/doc.xml", "schema/ui.xml"]);Sourcepub fn max_concurrent_tasks(self, count: usize) -> Self
pub fn max_concurrent_tasks(self, count: usize) -> Self
设置最大并发任务数
如果不设置,将根据 CPU 核心数自动计算。
§示例
let builder = ForgeRuntimeBuilder::new()
.max_concurrent_tasks(20);Sourcepub fn queue_size(self, size: usize) -> Self
pub fn queue_size(self, size: usize) -> Self
Sourcepub fn enable_monitoring(self, enable: bool) -> Self
pub fn enable_monitoring(self, enable: bool) -> Self
Sourcepub fn middleware_timeout_ms(self, timeout: u64) -> Self
pub fn middleware_timeout_ms(self, timeout: u64) -> Self
Sourcepub fn history_limit(self, limit: usize) -> Self
pub fn history_limit(self, limit: usize) -> Self
Sourcepub fn event_handler(
self,
handler: Arc<dyn EventHandler<Event> + Send + Sync>,
) -> Self
pub fn event_handler( self, handler: Arc<dyn EventHandler<Event> + Send + Sync>, ) -> Self
Sourcepub fn with_config(self, config: ForgeConfig) -> Self
pub fn with_config(self, config: ForgeConfig) -> Self
使用完整的 ForgeConfig
这会覆盖之前设置的所有配置项。
§示例
let config = ForgeConfig::for_environment(Environment::Production);
let builder = ForgeRuntimeBuilder::new()
.with_config(config);Sourcepub async fn from_config_file(path: &str) -> ForgeResult<Self>
pub async fn from_config_file(path: &str) -> ForgeResult<Self>
Sourcepub async fn build(self) -> ForgeResult<AnyRuntime>
pub async fn build(self) -> ForgeResult<AnyRuntime>
Trait Implementations§
Source§impl Default for ForgeRuntimeBuilder
impl Default for ForgeRuntimeBuilder
Source§fn default() -> ForgeRuntimeBuilder
fn default() -> ForgeRuntimeBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ForgeRuntimeBuilder
impl !RefUnwindSafe for ForgeRuntimeBuilder
impl Send for ForgeRuntimeBuilder
impl Sync for ForgeRuntimeBuilder
impl Unpin for ForgeRuntimeBuilder
impl !UnwindSafe for ForgeRuntimeBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
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>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage