Skip to content

Commit

Permalink
Merge pull request #15 from Be-ing/async_fn
Browse files Browse the repository at this point in the history
use `async fn` for async trait
  • Loading branch information
david-sawatzke authored Dec 29, 2024
2 parents 9aa2662 + 4468a91 commit 7dbc764
Showing 1 changed file with 12 additions and 3 deletions.
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

0 comments on commit 7dbc764

Please sign in to comment.