From 53a2fc2a3570e0f2258b9586d639c879067c2438 Mon Sep 17 00:00:00 2001 From: J / Jacob Babich Date: Sun, 12 Jul 2026 19:34:25 -0400 Subject: [PATCH] chore(protocol): address `async fn` in extension traits --- Cargo.lock | 1 + Cargo.toml | 1 + protocol/Cargo.toml | 1 + protocol/src/light.rs | 19 ++++++++++--------- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd2a240..0a22dd4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1758,6 +1758,7 @@ dependencies = [ "deranged", "derive_more", "ext-trait", + "futures", "palette", "serde", "snafu", diff --git a/Cargo.toml b/Cargo.toml index 86f7ff3..bd8ada0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ chrono-tz = "0.10.4" deranged = "0.5" derive_more = "2.1.0" ext-trait = "2.0.1" +futures = "0.3.32" mitsein = "0.9" palette = "0.7" proc-macro2 = "1.0.106" diff --git a/protocol/Cargo.toml b/protocol/Cargo.toml index 5b2ff86..6f5d426 100644 --- a/protocol/Cargo.toml +++ b/protocol/Cargo.toml @@ -12,6 +12,7 @@ serde = ["dep:serde"] deranged = { workspace = true } derive_more = { workspace = true } ext-trait = { workspace = true } +futures = { workspace = true } palette = { workspace = true } snafu = { workspace = true } strum = { workspace = true, features = ["derive"] } diff --git a/protocol/src/light.rs b/protocol/src/light.rs index 33fa767..576bcc4 100644 --- a/protocol/src/light.rs +++ b/protocol/src/light.rs @@ -1,7 +1,8 @@ use std::{error::Error, future::Future}; use deranged::RangedU16; -use snafu::{ResultExt, Snafu}; +use futures::TryFutureExt as _; +use snafu::{ResultExt as _, Snafu}; #[derive( Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, strum::Display, strum::EnumIs, @@ -44,15 +45,15 @@ pub trait GetState { #[ext_trait::extension(pub trait IsOff)] impl T { - async fn is_off(&self) -> Result { - Ok(self.get_state().await?.is_off()) + fn is_off(&self) -> impl Future> + Send { + self.get_state().map_ok(|state| state.is_off()) } } #[ext_trait::extension(pub trait IsOn)] impl T { - async fn is_on(&self) -> Result { - Ok(self.get_state().await?.is_on()) + fn is_on(&self) -> impl Future> + Send { + self.get_state().map_ok(|state| state.is_on()) } } @@ -63,15 +64,15 @@ pub trait SetState { #[ext_trait::extension(pub trait TurnOff)] impl T { - async fn turn_off(&mut self) -> Result<(), T::Error> { - self.set_state(State::Off).await + fn turn_off(&mut self) -> impl Future> + Send { + self.set_state(State::Off) } } #[ext_trait::extension(pub trait TurnOn)] impl T { - async fn turn_on(&mut self) -> Result<(), T::Error> { - self.set_state(State::On).await + fn turn_on(&mut self) -> impl Future> + Send { + self.set_state(State::On) } }