Closed jacobrosenthal closed 4 years ago
Ah, at first I didn't understand what this issue says. Now I understand.
I suppose, if you want hf2 code to be totally unaware of the type of transport used, you could use a technique something like this on the caller side.
struct MyHidDevice(HidDevice);
impl hf2::ReadWrite for MyHidDevice {
fn hf2_write(&self, data: &[u8]) -> std::result::Result<usize, Box<dyn std::error::Error>> {
//Ok(HidDevice::write(&self.0, data)?)
Ok(self.0.write(data)?)
}
fn hf2_read(&self, data: &mut [u8]) -> std::result::Result<usize, Box<dyn std::error::Error>> {
//Ok(HidDevice::read(&self.0, data)?)
Ok(self.0.read(data)?)
}
}
The type of the error will be also unknown to hf2 crate. So Box-ing of the error type is also required, I suppose. I still don't know better than this.
If we make our own trait its still unimplementable to downstream users because its a foreign trait. We could use a std library trait like io read write, but I was hoping to not tie to std features. Other ideas?