pub enum AnyRuntime {
Sync(ForgeRuntime),
Async(ForgeAsyncRuntime),
Actor(ForgeActorRuntime),
}Expand description
统一的运行时枚举
相比 Box<dyn RuntimeTrait>,这个枚举:
- 避免了动态分发的性能开销
- 保留了具体类型信息
- 支持类型特化优化
- 可以添加运行时特有的方法
§示例
let runtime = ForgeRuntimeBuilder::new().build().await?;
match &runtime {
AnyRuntime::Sync(rt) => println!("Using sync runtime"),
AnyRuntime::Async(rt) => println!("Using async runtime"),
AnyRuntime::Actor(rt) => println!("Using actor runtime"),
}Variants§
Implementations§
Source§impl AnyRuntime
impl AnyRuntime
Sourcepub fn runtime_type(&self) -> RuntimeType
pub fn runtime_type(&self) -> RuntimeType
获取运行时类型
Sourcepub fn as_sync(&self) -> Option<&ForgeRuntime>
pub fn as_sync(&self) -> Option<&ForgeRuntime>
尝试获取 Sync 运行时的引用
Sourcepub fn as_async(&self) -> Option<&ForgeAsyncRuntime>
pub fn as_async(&self) -> Option<&ForgeAsyncRuntime>
尝试获取 Async 运行时的引用
Sourcepub fn as_actor(&self) -> Option<&ForgeActorRuntime>
pub fn as_actor(&self) -> Option<&ForgeActorRuntime>
尝试获取 Actor 运行时的引用
Sourcepub fn as_sync_mut(&mut self) -> Option<&mut ForgeRuntime>
pub fn as_sync_mut(&mut self) -> Option<&mut ForgeRuntime>
尝试获取 Sync 运行时的可变引用
Sourcepub fn as_async_mut(&mut self) -> Option<&mut ForgeAsyncRuntime>
pub fn as_async_mut(&mut self) -> Option<&mut ForgeAsyncRuntime>
尝试获取 Async 运行时的可变引用
Sourcepub fn as_actor_mut(&mut self) -> Option<&mut ForgeActorRuntime>
pub fn as_actor_mut(&mut self) -> Option<&mut ForgeActorRuntime>
尝试获取 Actor 运行时的可变引用
Source§impl AnyRuntime
impl AnyRuntime
Sourcepub async fn dispatch(&mut self, transaction: Transaction) -> ForgeResult<()>
pub async fn dispatch(&mut self, transaction: Transaction) -> ForgeResult<()>
分发事务
Sourcepub async fn dispatch_with_meta(
&mut self,
transaction: Transaction,
description: String,
meta: Value,
) -> ForgeResult<()>
pub async fn dispatch_with_meta( &mut self, transaction: Transaction, description: String, meta: Value, ) -> ForgeResult<()>
分发事务(带元信息)
Sourcepub async fn command_with_meta(
&mut self,
command: Arc<dyn Command>,
description: String,
meta: Value,
) -> ForgeResult<()>
pub async fn command_with_meta( &mut self, command: Arc<dyn Command>, description: String, meta: Value, ) -> ForgeResult<()>
执行命令(带元信息)
Sourcepub async fn get_state(&self) -> ForgeResult<Arc<State>>
pub async fn get_state(&self) -> ForgeResult<Arc<State>>
获取当前状态
Sourcepub async fn get_tr(&self) -> ForgeResult<Transaction>
pub async fn get_tr(&self) -> ForgeResult<Transaction>
获取新事务
Sourcepub async fn doc(&self) -> ForgeResult<Arc<NodePool>>
pub async fn doc(&self) -> ForgeResult<Arc<NodePool>>
获取文档
Sourcepub async fn schema(&self) -> ForgeResult<Arc<Schema>>
pub async fn schema(&self) -> ForgeResult<Arc<Schema>>
获取 Schema
Sourcepub async fn undo(&mut self) -> ForgeResult<()>
pub async fn undo(&mut self) -> ForgeResult<()>
撤销
Sourcepub async fn redo(&mut self) -> ForgeResult<()>
pub async fn redo(&mut self) -> ForgeResult<()>
重做
Sourcepub async fn jump(&mut self, steps: isize) -> ForgeResult<()>
pub async fn jump(&mut self, steps: isize) -> ForgeResult<()>
跳转到指定历史位置
Sourcepub fn get_config(&self) -> &ForgeConfig
pub fn get_config(&self) -> &ForgeConfig
获取运行时配置
Sourcepub fn update_config(&mut self, config: ForgeConfig)
pub fn update_config(&mut self, config: ForgeConfig)
更新运行时配置
Sourcepub fn get_options(&self) -> RuntimeOptions
pub fn get_options(&self) -> RuntimeOptions
获取运行时选项
注意:Actor 运行时返回默认选项,因为它不直接持有 options
Sourcepub async fn destroy(&mut self) -> ForgeResult<()>
pub async fn destroy(&mut self) -> ForgeResult<()>
销毁运行时
Auto Trait Implementations§
impl Freeze for AnyRuntime
impl !RefUnwindSafe for AnyRuntime
impl Send for AnyRuntime
impl Sync for AnyRuntime
impl !Unpin for AnyRuntime
impl !UnwindSafe for AnyRuntime
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