rs_matter_stack/wireless/
gatt.rs1use core::future::Future;
2
3use rs_matter::error::Error;
4
5use crate::ble::GattPeripheral;
6
7use super::PreexistingWireless;
8
9pub trait GattTask {
12 async fn run<P>(&mut self, peripheral: P) -> Result<(), Error>
14 where
15 P: GattPeripheral;
16}
17
18impl<T> GattTask for &mut T
19where
20 T: GattTask,
21{
22 fn run<P>(&mut self, peripheral: P) -> impl Future<Output = Result<(), Error>>
23 where
24 P: GattPeripheral,
25 {
26 T::run(*self, peripheral)
27 }
28}
29
30pub trait Gatt {
33 async fn run<T>(&mut self, task: T) -> Result<(), Error>
35 where
36 T: GattTask;
37}
38
39impl<T> Gatt for &mut T
40where
41 T: Gatt,
42{
43 fn run<A>(&mut self, task: A) -> impl Future<Output = Result<(), Error>>
44 where
45 A: GattTask,
46 {
47 T::run(self, task)
48 }
49}
50
51impl<U, N, C, M, P> Gatt for PreexistingWireless<U, N, C, M, P>
52where
53 P: GattPeripheral,
54{
55 async fn run<T>(&mut self, mut task: T) -> Result<(), Error>
56 where
57 T: GattTask,
58 {
59 task.run(&mut self.gatt).await
60 }
61}