use core::future::Future;
use rs_matter::error::Error;
use crate::ble::GattPeripheral;
use super::PreexistingWireless;
pub trait GattTask {
async fn run<P>(&mut self, peripheral: P) -> Result<(), Error>
where
P: GattPeripheral;
}
impl<T> GattTask for &mut T
where
T: GattTask,
{
fn run<P>(&mut self, peripheral: P) -> impl Future<Output = Result<(), Error>>
where
P: GattPeripheral,
{
T::run(*self, peripheral)
}
}
pub trait Gatt {
async fn run<T>(&mut self, task: T) -> Result<(), Error>
where
T: GattTask;
}
impl<T> Gatt for &mut T
where
T: Gatt,
{
fn run<A>(&mut self, task: A) -> impl Future<Output = Result<(), Error>>
where
A: GattTask,
{
T::run(self, task)
}
}
impl<U, N, C, M, P> Gatt for PreexistingWireless<U, N, C, M, P>
where
P: GattPeripheral,
{
async fn run<T>(&mut self, mut task: T) -> Result<(), Error>
where
T: GattTask,
{
task.run(&mut self.gatt).await
}
}