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

nightly macro no-std ector-macros

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日

#58 in #actors

Download history 20/week @ 2024-03-28 16/week @ 2024-04-04

每月240次下载
用于ector

Apache-2.0

13KB
216

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文档。

社区

依赖项

~1.5MB
~35K SLoC