jacobrosenthal / hf2-rs

Microsoft HF2 HID Flashing Format for UF2 Bootloaders
49 stars 14 forks source link

remove hidapi as only using it for the trait #6

Closed jacobrosenthal closed 4 years ago

jacobrosenthal commented 4 years ago

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?

elfmimi commented 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.