ForgeRuntimeBuilder

Struct ForgeRuntimeBuilder 

Source
pub struct ForgeRuntimeBuilder;
Expand description

统一运行时构建器

提供多种创建运行时的方式:

  • auto(): 完全自动,根据系统资源选择
  • with_type(): 手动指定运行时类型
  • from_config(): 从配置创建

Implementations§

Source§

impl ForgeRuntimeBuilder

Source

pub async fn auto( options: Option<RuntimeOptions>, ) -> ForgeResult<Box<dyn RuntimeTrait>>

🎯 完全自动创建 - 检测系统资源并创建最优运行时

这是推荐的创建方式,会:

  1. 自动检测CPU核心数和内存大小
  2. 根据系统资源选择最优运行时类型
  3. 生成优化的配置参数
  4. 输出检测和配置信息
§参数
  • 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
// 💾 队列大小: 1600
Source

pub async fn with_type( runtime_type: RuntimeType, options: Option<RuntimeOptions>, ) -> ForgeResult<Box<dyn RuntimeTrait>>

使用指定的运行时类型创建

仍然会检测系统资源并优化配置,但强制使用指定的运行时类型。

§参数
  • runtime_type - 指定的运行时类型
§返回值
  • ForgeResult<Box<dyn RuntimeTrait>> - 运行时实例或错误
§示例
use mf_core::config::RuntimeType;

// 强制使用Actor运行时,但配置参数仍然自适应
let runtime = ForgeRuntimeBuilder::with_type(RuntimeType::Actor).await?;
Source

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§

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,