Skip to content
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "smart-leds-trait"
version = "0.3.0"
version = "0.4.0"
authors = ["David Sawatzke <[email protected]>"]
edition = "2021"
categories = [
Expand All @@ -17,4 +17,4 @@ repository = "https://github.com/smart-leds-rs/smart-leds-trait"
rgb = "0.8"

[features]
serde = ["rgb/serde"]
serde = ["rgb/serde"]
46 changes: 22 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,26 @@ pub trait SmartLedsWrite {
I: Into<Self::Color>;
}

pub mod asynch {
/// 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;
// 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>;
}
/// 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;
// 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>;
}