drmem_api/driver/
ro_device.rs1use crate::device;
2use std::future::Future;
3use std::marker::PhantomData;
4use std::pin::Pin;
5
6pub type ReportReading = Box<
8 dyn Fn(device::Value) -> Pin<Box<dyn Future<Output = ()> + Send>>
9 + Send
10 + Sync,
11>;
12
13pub struct ReadOnlyDevice<T: Into<device::Value> + Clone> {
17 report_chan: ReportReading,
18 phantom: PhantomData<T>,
19}
20
21impl<T> ReadOnlyDevice<T>
22where
23 T: Into<device::Value> + Clone,
24{
25 pub fn new(report_chan: ReportReading) -> Self {
27 ReadOnlyDevice {
28 report_chan,
29 phantom: PhantomData,
30 }
31 }
32
33 pub fn report_update(
36 &mut self,
37 value: T,
38 ) -> impl Future<Output = ()> + use<'_, T> {
39 (self.report_chan)(value.into())
40 }
41}