fix: make the light protocols return a Send future, resolving the warning that async fn in trait definitions is discouraged

This commit is contained in:
2025-04-22 00:48:48 -04:00
parent 18a0776edb
commit 2c8ece1168

View File

@@ -1,22 +1,22 @@
use std::error::Error; use std::{error::Error, future::Future};
use deranged::RangedU16; use deranged::RangedU16;
pub trait Light { pub trait Light {
type IsOnError: Error; type IsOnError: Error;
async fn is_on(&self) -> Result<bool, Self::IsOnError>; fn is_on(&self) -> impl Future<Output = Result<bool, Self::IsOnError>> + Send;
type IsOffError: Error; type IsOffError: Error;
async fn is_off(&self) -> Result<bool, Self::IsOffError>; fn is_off(&self) -> impl Future<Output = Result<bool, Self::IsOffError>> + Send;
type TurnOnError: Error; type TurnOnError: Error;
async fn turn_on(&mut self) -> Result<(), Self::TurnOnError>; fn turn_on(&mut self) -> impl Future<Output = Result<(), Self::TurnOnError>> + Send;
type TurnOffError: Error; type TurnOffError: Error;
async fn turn_off(&mut self) -> Result<(), Self::TurnOffError>; fn turn_off(&mut self) -> impl Future<Output = Result<(), Self::TurnOffError>> + Send;
type ToggleError: Error; type ToggleError: Error;
async fn toggle(&mut self) -> Result<(), Self::ToggleError>; fn toggle(&mut self) -> impl Future<Output = Result<(), Self::ToggleError>> + Send;
} }
#[derive(Debug, Clone, Copy, derive_more::From, derive_more::Into)] #[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 { pub trait KelvinLight: Light {
type TurnToKelvinError: Error; 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<Output = Result<(), Self::TurnToKelvinError>> + Send;
} }
// TODO: replace with a type from a respected and useful library // 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 { pub trait RgbLight: Light {
type TurnToRgbError: Error; 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<Output = Result<(), Self::TurnToRgbError>> + Send;
} }