#actor-framework #actor #embedded-devices #async #actor-system #embedded

nightly no-std ector

Ector 是一个开源的异步、无分配嵌入式设备 Actor 框架

6 个版本 (破坏性更新)

0.5.0 2023 年 9 月 22 日
0.4.0 2023 年 4 月 28 日
0.3.0 2023 年 4 月 27 日
0.2.0 2023 年 4 月 27 日
0.1.0 2022 年 6 月 14 日

#1326 in 异步

Download history 8/week @ 2024-03-26 30/week @ 2024-04-02

每月 207 次下载

Apache-2.0

33KB
708

Ector 是一个开源的异步、无分配嵌入式设备 Actor 框架。

CI crates.io docs.rs Matrix

Ector 是一个开源的异步、无分配嵌入式设备 Actor 框架。它集成了 embassy,一个嵌入式异步项目。

Actor 系统

一个 actor 系统 是一个框架,它允许在狭窄的上下文中隔离状态,使得推理系统更加容易。在一个 actor 系统中,主要的组件是 Actor,它代表了状态使用的边界。每个 actor 都有对其自身状态的独家访问权,并且仅通过消息传递与其他 actor 进行通信。

示例

#![macro_use]
#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]

use ector::*;

/// A Counter that we wish to create an Actor for.
pub struct Counter {
    count: u32,
}

// The message our actor will handle.
pub struct Increment;

/// An Actor implements the Actor trait.
impl Actor for Counter {
    /// The Message associated type is the message types that the Actor can receive.
    type Message = Increment;

    /// An actor has to implement the on_mount method. on_mount() is invoked when the internals of an actor is ready,
    /// and the actor can begin to receive messages from an inbox.
    ///
    /// The following arguments are provided:
    /// * The address to 'self'
    /// * An inbox from which the actor can receive messages
    async fn on_mount<M>(&mut self, _: Address<Self::Message<'m>>, mut inbox: M) -> !
        where M: Inbox<Self::Message<'m>> {
    {
        loop {
            // Await the next message and increment the counter
            let _ = inbox.next().await;
            self.count += 1;
        }
    }
}

 /// The entry point of the application is using the embassy runtime.
 #[embassy::main]
 async fn main(spawner: embassy::executor::Spawner) {

     // Mounting the Actor will spawn an embassy task
     let addr = ector::actor!(spawner, counter, Counter, Counter { count  0 });

     // The actor address may be used in any embassy task to communicate with the actor.
     let _ = addr.notify(Increment).await;
 }

构建

要构建 ector,您必须安装 nightly rust 工具链。一旦安装,您可以通过运行以下命令来构建和测试框架:

cargo test

目录布局

  • ector - 一个 actor 框架
  • macros - drogue-device 和应用程序代码使用的宏

贡献

请参阅文档 CONTRIBUTING.md

社区

依赖关系

~4.5MB
~96K SLoC