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

Switch to AFIT; upgrade to e-io 0.5 #56

Merged
merged 17 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.26.0] - 2023-09-02
* MSRV raised to 1.71
* Breaking change: All traits converted to AFIT, except `Unblocker`, which needs to compile with stable Rust
* Breaking change: Upgraded to `embedded-io` 0.5 and `embedded-io-async` 0.5
* Upgraded `strum` and `strum-macros` to 0.25
* Breaking change: OTA: GAT `Ota::Update` now parametric over lifetime and no longer returned by `&mut` ref
* Breaking change: MQTT: GAT `Connection::Message` now parametric over lifetime
* Breaking change: All pub structs in `utils::asyncify` that implement the `Future` trait are now private and wrapped with async methods
* Breaking change: Removed structs `Blocking` and `TrivialAsync`, as well as all trait implementations on them, because their usefulness was questionable
* Breaking change: Removed the deprecated module `httpd` and the dependency on `anyhow`

## [0.25.3] - 2023-07-05
* Compatibility with latest Rust nightly Clippy (fixes the "usage of `Arc<T>` where `T` is not `Send` or `Sync`" error)

Expand Down
22 changes: 10 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,30 @@ description = "A set of traits for services higher level than embedded-hal and t
repository = "https://github.com/esp-rs/embedded-svc"
license = "MIT OR Apache-2.0"
readme = "README.md"
rust-version = "1.66"
rust-version = "1.71"

[features]
default = ["std", "use_serde", "use_strum", "use_numenum", "log"]

std = ["alloc", "embedded-io/std", "serde/std", "anyhow/std", "strum?/std", "num_enum?/std"]
alloc = ["anyhow", "embedded-io/alloc", "serde/alloc", "defmt?/alloc"]
nightly = []
std = ["alloc", "embedded-io/std", "embedded-io-async?/std", "serde/std", "strum?/std", "num_enum?/std"]
alloc = ["embedded-io/alloc", "embedded-io-async?/alloc", "serde/alloc", "defmt?/alloc"]
nightly = ["embedded-io-async"]
experimental = []
embedded-io-async = ["embedded-io/async"]
use_serde = ["enumset/serde", "no-std-net/serde", "heapless/serde"]
use_strum = ["strum", "strum_macros"]
use_numenum = ["num_enum"]
defmt = ["dep:defmt", "heapless/defmt", "heapless/defmt-impl"]
log = ["dep:log"]
defmt = ["dep:defmt", "heapless/defmt", "heapless/defmt-impl", "embedded-io/defmt-03", "embedded-io-async?/defmt-03"]

[dependencies]
heapless = { version = "0.7" }
embedded-io = { version = "0.4", default-features = false }
embedded-io = { version = "0.5", default-features = false }
embedded-io-async = { version = "0.5", default-features = false, optional = true }
log = { version = "0.4", default-features = false, optional = true }
no-std-net = { version = "0.5", default-features = false }
serde = { version = "1", default-features = false, features = ["derive"] }
atomic-waker = { version = "1.1.1", default-features = false }
enumset = { version = "1", default-features = false }
strum = { version = "0.23", default-features = false, optional = true, features = ["derive"] }
strum_macros = { version = "0.23", optional = true }
num_enum = { version = "0.5", default-features = false, optional = true }
anyhow = { version = "1", default-features = false, optional = true } # Only used by the deprecated httpd module
strum = { version = "0.25", default-features = false, optional = true, features = ["derive"] }
strum_macros = { version = "0.25", optional = true }
num_enum = { version = "0.7", default-features = false, optional = true }
defmt = { version = "0.3", optional = true }
58 changes: 12 additions & 46 deletions src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,16 @@ where

#[cfg(feature = "nightly")]
pub mod asynch {
use core::future::Future;

use super::*;

pub trait Eth {
type Error: Debug;

type StartFuture<'a>: Future<Output = Result<(), Self::Error>>
where
Self: 'a;

type StopFuture<'a>: Future<Output = Result<(), Self::Error>>
where
Self: 'a;

type IsStartedFuture<'a>: Future<Output = Result<bool, Self::Error>>
where
Self: 'a;

type IsConnectedFuture<'a>: Future<Output = Result<bool, Self::Error>>
where
Self: 'a;

fn start(&mut self) -> Self::StartFuture<'_>;
fn stop(&mut self) -> Self::StopFuture<'_>;
async fn start(&mut self) -> Result<(), Self::Error>;
async fn stop(&mut self) -> Result<(), Self::Error>;

fn is_started(&self) -> Self::IsStartedFuture<'_>;
fn is_connected(&self) -> Self::IsConnectedFuture<'_>;
async fn is_started(&self) -> Result<bool, Self::Error>;
async fn is_connected(&self) -> Result<bool, Self::Error>;
}

impl<E> Eth for &mut E
Expand All @@ -71,36 +53,20 @@ pub mod asynch {
{
type Error = E::Error;

type StartFuture<'a> = E::StartFuture<'a>
where
Self: 'a;

type StopFuture<'a> = E::StopFuture<'a>
where
Self: 'a;

type IsStartedFuture<'a> = E::IsStartedFuture<'a>
where
Self: 'a;

type IsConnectedFuture<'a> = E::IsConnectedFuture<'a>
where
Self: 'a;

fn start(&mut self) -> Self::StartFuture<'_> {
(**self).start()
async fn start(&mut self) -> Result<(), Self::Error> {
(**self).start().await
}

fn stop(&mut self) -> Self::StopFuture<'_> {
(**self).stop()
async fn stop(&mut self) -> Result<(), Self::Error> {
(**self).stop().await
}

fn is_started(&self) -> Self::IsStartedFuture<'_> {
(**self).is_started()
async fn is_started(&self) -> Result<bool, Self::Error> {
(**self).is_started().await
}

fn is_connected(&self) -> Self::IsConnectedFuture<'_> {
(**self).is_connected()
async fn is_connected(&self) -> Result<bool, Self::Error> {
(**self).is_connected().await
}
}
}
53 changes: 17 additions & 36 deletions src/event_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,22 @@ where
pub mod asynch {
pub use super::{ErrorType, Spin};

use core::future::Future;

pub trait Sender {
type Data: Send;
type Result: Send;

type SendFuture<'a>: Future + Send
where
Self: 'a;

fn send(&self, value: Self::Data) -> Self::SendFuture<'_>;
async fn send(&self, value: Self::Data) -> Self::Result;
}

impl<S> Sender for &mut S
where
S: Sender,
{
type Data = S::Data;
type Result = S::Result;

type SendFuture<'a>
= S::SendFuture<'a> where Self: 'a;

fn send(&self, value: Self::Data) -> Self::SendFuture<'_> {
(**self).send(value)
async fn send(&self, value: Self::Data) -> Self::Result {
(**self).send(value).await
}
}

Expand All @@ -146,55 +139,43 @@ pub mod asynch {
S: Sender,
{
type Data = S::Data;
type Result = S::Result;

type SendFuture<'a>
= S::SendFuture<'a> where Self: 'a;

fn send(&self, value: Self::Data) -> Self::SendFuture<'_> {
(*self).send(value)
async fn send(&self, value: Self::Data) -> Self::Result {
(*self).send(value).await
}
}

pub trait Receiver {
type Data: Send;

type RecvFuture<'a>: Future<Output = Self::Data> + Send
where
Self: 'a;
type Result: Send;

fn recv(&self) -> Self::RecvFuture<'_>;
async fn recv(&self) -> Self::Result;
}

impl<R> Receiver for &mut R
where
R: Receiver,
{
type Data = R::Data;
type Result = R::Result;

type RecvFuture<'a>
= R::RecvFuture<'a> where Self: 'a;

fn recv(&self) -> Self::RecvFuture<'_> {
(**self).recv()
async fn recv(&self) -> Self::Result {
(**self).recv().await
}
}

impl<R> Receiver for &R
where
R: Receiver,
{
type Data = R::Data;

type RecvFuture<'a>
= R::RecvFuture<'a> where Self: 'a;
type Result = R::Result;

fn recv(&self) -> Self::RecvFuture<'_> {
(*self).recv()
async fn recv(&self) -> Self::Result {
(*self).recv().await
}
}

pub trait EventBus<P>: ErrorType {
type Subscription: Receiver<Data = P>;
type Subscription: Receiver<Result = P>;

fn subscribe(&self) -> Result<Self::Subscription, Self::Error>;
}
Expand Down
Loading