chore(protocol): address async fn in extension traits

This commit is contained in:
J / Jacob Babich
2026-07-12 19:34:25 -04:00
parent 044243ae3c
commit 53a2fc2a35
4 changed files with 13 additions and 9 deletions

View File

@@ -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: GetState> T {
async fn is_off(&self) -> Result<bool, T::Error> {
Ok(self.get_state().await?.is_off())
fn is_off(&self) -> impl Future<Output = Result<bool, T::Error>> + Send {
self.get_state().map_ok(|state| state.is_off())
}
}
#[ext_trait::extension(pub trait IsOn)]
impl<T: GetState> T {
async fn is_on(&self) -> Result<bool, T::Error> {
Ok(self.get_state().await?.is_on())
fn is_on(&self) -> impl Future<Output = Result<bool, T::Error>> + 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: SetState> T {
async fn turn_off(&mut self) -> Result<(), T::Error> {
self.set_state(State::Off).await
fn turn_off(&mut self) -> impl Future<Output = Result<(), T::Error>> + Send {
self.set_state(State::Off)
}
}
#[ext_trait::extension(pub trait TurnOn)]
impl<T: SetState> T {
async fn turn_on(&mut self) -> Result<(), T::Error> {
self.set_state(State::On).await
fn turn_on(&mut self) -> impl Future<Output = Result<(), T::Error>> + Send {
self.set_state(State::On)
}
}