use crate::device;
use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;
pub type ReportReading = Box<
dyn Fn(device::Value) -> Pin<Box<dyn Future<Output = ()> + Send>>
+ Send
+ Sync,
>;
pub struct ReadOnlyDevice<T: Into<device::Value> + Clone> {
report_chan: ReportReading,
phantom: PhantomData<T>,
}
impl<T> ReadOnlyDevice<T>
where
T: Into<device::Value> + Clone,
{
pub fn new(report_chan: ReportReading) -> Self {
ReadOnlyDevice {
report_chan,
phantom: PhantomData,
}
}
pub fn report_update(
&mut self,
value: T,
) -> impl Future<Output = ()> + use<'_, T> {
(self.report_chan)(value.into())
}
}