async_hid/
device.rs

1use std::future::Future;
2
3use crate::backend::{Backend, DynBackend};
4use crate::traits::{AsyncHidRead, AsyncHidWrite};
5use crate::HidResult;
6
7/// A reader than can be used to read input reports from a HID device using [AsyncHidRead::read_input_report]
8#[repr(transparent)]
9pub struct DeviceReader(pub(crate) <DynBackend as Backend>::Reader);
10
11/// A writer than can be used to write output reports from a HID device using [AsyncHidWrite::write_output_report]
12#[repr(transparent)]
13pub struct DeviceWriter(pub(crate) <DynBackend as Backend>::Writer);
14
15/// Combination of [DeviceReader] and [DeviceWriter]
16///
17/// Can either be destructured or used directly
18pub type DeviceReaderWriter = (DeviceReader, DeviceWriter);
19
20impl AsyncHidRead for DeviceReader {
21    #[inline]
22    fn read_input_report<'a>(&'a mut self, buf: &'a mut [u8]) -> impl Future<Output = HidResult<usize>> + Send + 'a {
23        self.0.read_input_report(buf)
24    }
25}
26
27impl AsyncHidWrite for DeviceWriter {
28    #[inline]
29    fn write_output_report<'a>(&'a mut self, buf: &'a [u8]) -> impl Future<Output = HidResult<()>> + Send + 'a {
30        self.0.write_output_report(buf)
31    }
32}
33
34impl AsyncHidRead for DeviceReaderWriter {
35    #[inline]
36    fn read_input_report<'a>(&'a mut self, buf: &'a mut [u8]) -> impl Future<Output = HidResult<usize>> + Send + 'a {
37        self.0.read_input_report(buf)
38    }
39}
40
41impl AsyncHidWrite for DeviceReaderWriter {
42    #[inline]
43    fn write_output_report<'a>(&'a mut self, buf: &'a [u8]) -> impl Future<Output = HidResult<()>> + Send + 'a {
44        self.1.write_output_report(buf)
45    }
46}