Skip to content

use async fn for async trait #15

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

Merged
merged 1 commit into from
Dec 29, 2024
Merged
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
15 changes: 12 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,25 @@ pub trait SmartLedsWrite {
}

pub mod asynch {
use core::future::Future;

/// An async trait that Smart Led Drivers implement
///
/// The amount of time each iteration of `iterator` might take is undefined.
/// Drivers, where this might lead to issues, aren't expected to work in all cases.
pub trait SmartLedsWriteAsync {
type Error;
type Color;
fn write<T, I>(&mut self, iterator: T) -> impl Future<Output = Result<(), Self::Error>>
// The async_fn_in_trait warning doesn't really matter for embedded cases because
// no_std async executors don't require futures to be Send. Also, embedded-hal-async
// does not have Send bounds in its traits, so the HAL functions called in
// implementations of this trait wouldn't return Send futures anyway. It's
// questionable if it would be desirable for embedded HALs to return a Send future
// for the write function for a peripheral because you probably don't want to
// write data to the same peripheral from multiple threads simultaneously and have
// the data get interleaved, nor have the embedded HAL implement a synchronization
// mechanism with a run time cost to avoid that.
// https://github.com/rust-embedded/embedded-hal/pull/515#issuecomment-1763525962
#[allow(async_fn_in_trait)]
async fn write<T, I>(&mut self, iterator: T) -> Result<(), Self::Error>
where
T: IntoIterator<Item = I>,
I: Into<Self::Color>;
Expand Down