Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update embassy dependencies #19

Merged
merged 12 commits into from
Oct 27, 2024
3 changes: 0 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ In any case, you will need:

* **A supported development kit** - Drogue device is about ... devices, so having a kit that you can run will help you test and validate code for peripherals (see [examples](examples/) for what boards we have working examples for).

* **Rust Nightly** – Drogue-device relies on features only available in Rust nightly. You can use nightly either by running all
rust commands with `+nightly`, or just change default to nightly by running `rustup default nightly`.

* **An IDE** – Whatever works best for you. Eclipse, Emacs, IntelliJ, Vim, … [^1] should all be usable with this
project. We do not require any specific IDE. We also do not commit any IDE specific files either.

Expand Down
27 changes: 10 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ector is an open source async, no-alloc actor framework for embedded devices.
# Ector is an open source async, no-alloc actor framework for embedded devices

[![CI](https://github.com/drogue-iot/ector/actions/workflows/ci.yaml/badge.svg)](https://github.com/drogue-iot/ector/actions/workflows/ci.yaml)
[![crates.io](https://img.shields.io/crates/v/ector.svg)](https://crates.io/crates/ector)
Expand All @@ -15,11 +15,7 @@ Each actor has exclusive access to its own state and only communicates with othe

## Example

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

```rust ignore
use ector::*;

/// A Counter that we wish to create an Actor for.
Expand All @@ -41,9 +37,8 @@ impl Actor for Counter {
/// 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>> {
{
async fn on_mount<M>(&mut self, _: DynamicAddress<Self::Message>, mut inbox: M) -> !
where M: Inbox<Self::Message> {
loop {
// Await the next message and increment the counter
let _ = inbox.next().await;
Expand All @@ -53,11 +48,11 @@ impl Actor for Counter {
}

/// The entry point of the application is using the embassy runtime.
#[embassy::main]
async fn main(spawner: embassy::executor::Spawner) {
#[embassy_executor::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 });
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;
Expand All @@ -66,19 +61,17 @@ impl Actor for Counter {

## Building

To build `ector`, you must install the [nightly rust toolchain](https://rustup.rs/). Once
installed, you can build and test the framework by running
You can build and test the framework by running

~~~shell
```shell
cargo test
~~~
```

## Directory layout

* `ector` - an actor framework
* `macros` - macros used by drogue-device and application code


## Contributing

See the document [CONTRIBUTING.md](CONTRIBUTING.md).
Expand Down
35 changes: 24 additions & 11 deletions ector/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "ector"
version = "0.5.0"
version = "0.6.0"
description = "Ector is an open source async, no-alloc actor framework for embedded devices."
documentation = "https://docs.rs/ector"
readme = "../README.md"
Expand All @@ -15,27 +15,40 @@ exclude = [".github"]
doctest = false

[dependencies]
embassy-executor = { version = "0.4", default-features = false }
embassy-sync = { version = "0.5", default-features = false }
atomic-polyfill = "1"
embassy-executor = { version = "0.6", default-features = false }
embassy-sync = { version = "0.6", default-features = false }
portable-atomic = { version = "1.3", default-features = false }

log = { version = "0.4", optional = true }
defmt = { version = "0.3", optional = true }

ector-macros = { version = "0.5.0", path = "../macros" }
futures = { version = "0.3", default-features = false }
static_cell = "1.0.0"
static_cell = "2.1"


[dev-dependencies]
embassy-executor = { version = "0.4.0", default-features = false, features = ["integrated-timers", "arch-std", "executor-thread"]}
embassy-time = { version = "0.2.0", default-features = false, features = ["std"] }
futures = { version = "0.3", default-features = false, features = ["executor"] }
critical-section = { version = "1.1", features = ["std"] }
embassy-executor = { version = "0.6.0", default-features = false, features = [
"integrated-timers",
"arch-std",
"executor-thread",
] }
embassy-time = { version = "0.3.2", default-features = false, features = [
"std",
] }
futures = { version = "0.3.31", default-features = false, features = [
"executor",
] }
critical-section = { version = "1.2.0", features = ["std"] }
ector = { path = ".", features = ["std", "log", "time", "test-utils"] }

[features]
default = [ "std", "log", "time" ]
std = ["embassy-executor/integrated-timers", "embassy-executor/arch-std", "embassy-time/std", "critical-section/std"]
default = ["std", "log", "time"]
std = [
"embassy-executor/integrated-timers",
"embassy-executor/arch-std",
"embassy-time/std",
"critical-section/std",
]
test-utils = []
time = []
5 changes: 5 additions & 0 deletions ector/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
if std::env::var_os("CARGO_FEATURE_NIGHTLY").is_some() {
println!("cargo:rustc-cfg=nightly");
}
}
5 changes: 0 additions & 5 deletions ector/examples/cancel_panic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
//! Example where cancellation will cause a panic

#![macro_use]
#![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use {
ector::*,
embassy_time::{Duration, Timer},
Expand Down
5 changes: 0 additions & 5 deletions ector/examples/macro-usage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#![macro_use]
#![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use {
ector::{mutex::NoopRawMutex, *},
embassy_time::{Duration, Timer},
Expand Down
5 changes: 0 additions & 5 deletions ector/examples/pingpong.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#![macro_use]
#![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use {
ector::*,
embassy_time::{Duration, Ticker},
Expand Down
5 changes: 0 additions & 5 deletions ector/examples/request.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#![macro_use]
#![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use {
ector::*,
embassy_time::{Duration, Timer},
Expand Down
5 changes: 0 additions & 5 deletions ector/examples/send.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#![macro_use]
#![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

use ector::mutex::CriticalSectionRawMutex;

use {
Expand Down
14 changes: 12 additions & 2 deletions ector/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ impl<'a, M, R> ActorRequest<M, R> for DynamicSender<'a, Request<M, R>> {

// We guarantee that channel lives until we've been notified on it, at which
// point its out of reach for the replier.
let reply_to = unsafe { core::mem::transmute(&sender) };
let reply_to = unsafe {
core::mem::transmute::<
&embassy_sync::channel::DynamicSender<'_, R>,
&embassy_sync::channel::DynamicSender<'_, R>,
>(&sender)
};
let message = Request::new(message, reply_to);
self.notify(message).await;
let res = channel.receive().await;
Expand Down Expand Up @@ -121,7 +126,12 @@ where

// We guarantee that channel lives until we've been notified on it, at which
// point its out of reach for the replier.
let reply_to = unsafe { core::mem::transmute(&sender) };
let reply_to = unsafe {
core::mem::transmute::<
&embassy_sync::channel::DynamicSender<'_, R>,
&embassy_sync::channel::DynamicSender<'_, R>,
>(&sender)
};
let message = Request::new(message, reply_to);
self.notify(message).await;
let res = channel.receive().await;
Expand Down
52 changes: 52 additions & 0 deletions ector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,58 @@ pub mod mutex {
pub mod testutils;

/// Spawn an actor given a spawner and the actors name, type and instance.
///
/// actor! is a macro that simplifies the process of spawning an actor. It creates a new ActorContext and spawns the actor with the given spawner.
///
/// # Arguments
///
/// `actor!(spawner, name, type, instance, [mutex type], [queue size]);`
///
/// | | |
/// | ----------- | ------------------------------------------------------------------------------------------------------ |
/// | spawner | The spawner to use to spawn the actor (i.e. embassy_executor::Spawner) |
/// | name | The name of the actor, used to generate the task name |
/// | type | The type of the actor, must implement the Actor trait |
/// | instance | The instance of the actor to spawn |
/// | mutex type | The type of mutex to use for the actor. (defaults to embassy_sync::blocking_mutex::raw::NoopRawMutex) |
/// | queue size | The size of the actor's message queue. (defaults to 1) |
///
///
/// # Example
///
/// ```rust ignore
/// use ector::*;
///
/// type Addr = DynamicAddress<Request<String, String>>;
///
/// struct Server;
///
/// impl Actor for Server {
/// type Message = Request<String, String>;
/// async fn on_mount<M>(&mut self, _: Addr, mut inbox: M) -> !
/// where
/// M: Inbox<Self::Message>,
/// {
/// println!("Server started!");
///
/// loop {
/// let motd = inbox.next().await;
/// let m = motd.as_ref().clone();
/// motd.reply(m).await;
/// }
/// }
/// }
///
/// #[embassy_executor::main]
/// async fn main(s: embassy_executor::Spawner) {
/// let server_addr: Addr = actor!(s, server, Server, Server).into();
/// loop {
/// let r = server_addr.request("Hello".to_string()).await;
/// println!("Server returned {}", r);
/// }
/// }
///
/// ```
#[macro_export]
macro_rules! actor {
($spawner:ident, $name:ident, $ty:ty, $instance:expr) => {{
Expand Down
2 changes: 1 addition & 1 deletion ector/src/testutils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use {
crate::{Actor, DynamicAddress, Inbox},
atomic_polyfill::{AtomicBool, Ordering},
core::{cell::RefCell, future::Future, pin::Pin},
embassy_executor::{raw, Spawner},
embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, signal::Signal},
portable_atomic::{AtomicBool, Ordering},
static_cell::StaticCell,
std::{cell::UnsafeCell, marker::PhantomData, vec::Vec},
};
Expand Down
86 changes: 0 additions & 86 deletions ector/tests/integration_tests.rs

This file was deleted.

2 changes: 0 additions & 2 deletions ector/tests/notifications.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![allow(dead_code)]
#![allow(incomplete_features)]
#![warn(unused_attributes)]
#![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)]

use ector::{
testutils::{DummyActor, *},
Expand Down
1 change: 1 addition & 0 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ proc-macro2 = "1.0"

[features]
std = []
nightly = []
2 changes: 1 addition & 1 deletion macros/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn transform_sig(sig: &mut Signature) {
.predicates
.push(parse_quote_spanned!(bound_span=> Self: 'm));

for (_, arg) in sig.inputs.iter_mut().enumerate() {
for arg in sig.inputs.iter_mut() {
match arg {
FnArg::Receiver(arg) => {
let s = arg.span();
Expand Down
Loading
Loading