kevinmehall / nusb

A new pure-Rust library for cross-platform low-level access to USB devices.
Apache License 2.0
199 stars 26 forks source link

`Interface::bulk_out()` - support also slices as an argument #61

Open XVilka opened 4 months ago

XVilka commented 4 months ago

Currently, the method signature is

pub fn bulk_out(&self, endpoint: u8, buf: Vec<u8>)

But it makes a requirement to allocate the buf, which isn't always welcome. I suggest also to support specifying buf as &[u8] slice.

kevinmehall commented 4 months ago

Unfortunately an API taking a borrowed slice is not safe when it comes to async IO in Rust, because you can leak the Future and regain mutable access to the buffer while the kernel continues to read from it. It's the same problem as io-uring and other completion-based IO.