pub struct ForgeRuntimeBuilder;Expand description
统一运行时构建器
提供多种创建运行时的方式:
auto(): 完全自动,根据系统资源选择with_type(): 手动指定运行时类型from_config(): 从配置创建
Implementations§
Source§impl ForgeRuntimeBuilder
impl ForgeRuntimeBuilder
Sourcepub async fn auto(
options: Option<RuntimeOptions>,
) -> ForgeResult<Box<dyn RuntimeTrait>>
pub async fn auto( options: Option<RuntimeOptions>, ) -> ForgeResult<Box<dyn RuntimeTrait>>
🎯 完全自动创建 - 检测系统资源并创建最优运行时
这是推荐的创建方式,会:
- 自动检测CPU核心数和内存大小
- 根据系统资源选择最优运行时类型
- 生成优化的配置参数
- 输出检测和配置信息
§参数
options- 可选的运行时选项(为None时使用默认值)
§返回值
ForgeResult<Box<dyn RuntimeTrait>>- 运行时实例或错误
§示例
// 使用默认选项
let runtime = ForgeRuntimeBuilder::auto(None).await?;
// 使用自定义选项
let options = RuntimeOptions::default();
let runtime = ForgeRuntimeBuilder::auto(Some(options)).await?;
// 输出示例:
// 🖥️ 系统资源: 8 核心, 16 GB 内存 (高性能)
// ⚡ 运行时类型: Actor
// 📊 并发任务数: 6
// 💾 队列大小: 1600Sourcepub async fn with_type(
runtime_type: RuntimeType,
options: Option<RuntimeOptions>,
) -> ForgeResult<Box<dyn RuntimeTrait>>
pub async fn with_type( runtime_type: RuntimeType, options: Option<RuntimeOptions>, ) -> ForgeResult<Box<dyn RuntimeTrait>>
Sourcepub async fn from_config(
config: ForgeConfig,
options: Option<RuntimeOptions>,
) -> ForgeResult<Box<dyn RuntimeTrait>>
pub async fn from_config( config: ForgeConfig, options: Option<RuntimeOptions>, ) -> ForgeResult<Box<dyn RuntimeTrait>>
从配置创建运行时
如果配置中的运行时类型为 Auto,会自动检测系统资源。
§参数
config- Forge配置options- 可选的运行时选项(为None时使用默认值)
§返回值
ForgeResult<Box<dyn RuntimeTrait>>- 运行时实例或错误
§示例
let config = ForgeConfig {
runtime: RuntimeConfig {
runtime_type: RuntimeType::Auto, // 自动检测
},
..Default::default()
};
let runtime = ForgeRuntimeBuilder::from_config(config, None).await?;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