Skip to content

Commit 4468a91

Browse files
committed
use async fn for async trait
for readability A Send variant may be nice to use with Embassy's SendSpawner. However, embedded-hal-async traits don't have Send variants, so it's unlikely the that the drivers called in the impl's of this trait would have async fn's that return Send Futures. You probably don't want to be writing different frames to one LED device from multiple threads simultaneously anyway; that would require the driver to implement synchronization to avoid interleaving of separate frames, which would add a run time cost.
1 parent 9aa2662 commit 4468a91

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,25 @@ pub trait SmartLedsWrite {
3737
}
3838

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

0 commit comments

Comments
 (0)