From 2c8ece1168f1c530a06819695c7c75ad09995fb2 Mon Sep 17 00:00:00 2001 From: Jacob Date: Tue, 22 Apr 2025 00:48:48 -0400 Subject: [PATCH] fix: make the light protocols return a `Send` future, resolving the warning that `async fn` in trait definitions is discouraged --- protocol/src/light.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/protocol/src/light.rs b/protocol/src/light.rs index 2825800..6a1c1d9 100644 --- a/protocol/src/light.rs +++ b/protocol/src/light.rs @@ -1,22 +1,22 @@ -use std::error::Error; +use std::{error::Error, future::Future}; use deranged::RangedU16; pub trait Light { type IsOnError: Error; - async fn is_on(&self) -> Result; + fn is_on(&self) -> impl Future> + Send; type IsOffError: Error; - async fn is_off(&self) -> Result; + fn is_off(&self) -> impl Future> + Send; type TurnOnError: Error; - async fn turn_on(&mut self) -> Result<(), Self::TurnOnError>; + fn turn_on(&mut self) -> impl Future> + Send; type TurnOffError: Error; - async fn turn_off(&mut self) -> Result<(), Self::TurnOffError>; + fn turn_off(&mut self) -> impl Future> + Send; type ToggleError: Error; - async fn toggle(&mut self) -> Result<(), Self::ToggleError>; + fn toggle(&mut self) -> impl Future> + Send; } #[derive(Debug, Clone, Copy, derive_more::From, derive_more::Into)] @@ -24,7 +24,10 @@ pub struct Kelvin(pub RangedU16<2000, 10000>); pub trait KelvinLight: Light { type TurnToKelvinError: Error; - async fn turn_to_kelvin(&mut self, temperature: Kelvin) -> Result<(), Self::TurnToKelvinError>; + fn turn_to_kelvin( + &mut self, + temperature: Kelvin, + ) -> impl Future> + Send; } // TODO: replace with a type from a respected and useful library @@ -33,5 +36,8 @@ pub struct Rgb(pub u8, pub u8, pub u8); pub trait RgbLight: Light { type TurnToRgbError: Error; - async fn turn_to_rgb(&mut self, color: Rgb) -> Result<(), Self::TurnToRgbError>; + fn turn_to_rgb( + &mut self, + color: Rgb, + ) -> impl Future> + Send; }