The EndpointRead struct wraps a Bulk or Interrupt IN Endpoint to provide a high-level buffered reading API. It manages multiple concurrent transfers to maximize throughput.
Depending on your enabled cargo features, you can use it with standard synchronous IO traits or asynchronous IO traits:
- Blocking IO: Implements
std::io::Read and std::io::BufRead. - Async IO (Tokio): If the
tokio feature is enabled, it implements tokio::io::AsyncRead and tokio::io::AsyncBufRead. - Async IO (Smol): If the
smol feature is enabled, it implements futures_io::AsyncRead and futures_io::AsyncBufRead.
By default, EndpointRead ignores USB packet boundaries. To observe short or zero-length packets as delimiters, use the until_short_packet() method to get an EndpointReadUntilShortPacket adapter.
// Example initialization (assuming endpoint is already obtained)
let mut reader = EndpointRead::new(endpoint, 4096);
// For blocking IO
let mut buffer = [0u8; 1024];
let n = reader.read(&mut buffer)?;