pub struct EndpointRead<EpType: BulkOrInterrupt> { /* private fields */ }
Expand description
Wrapper for a Bulk or Interrupt IN Endpoint
that
manages transfers to provide a higher-level buffered API.
Most of the functionality of this type is provided through standard IO traits; you’ll want to use one of the following:
std::io::Read
andBufRead
for blocking IO.- With the
tokio
cargo feature,tokio::io::AsyncRead
andAsyncBufRead
for async IO. Tokio also providesAsyncReadExt
andAsyncBufReadExt
with additional methods. - With the
smol
cargo feature,futures_io::AsyncRead
andAsyncBufRead
for async IO.futures_lite
providesAsyncReadExt
andAsyncBufReadExt
with additional methods.
By default, this type ignores USB packet lengths and boundaries. For protocols
that use short or zero-length packets as delimiters, you can use the
until_short_packet()
method to get an
EndpointReadUntilShortPacket
adapter
that observes these delimiters.
Implementations§
Source§impl<EpType: BulkOrInterrupt> EndpointRead<EpType>
impl<EpType: BulkOrInterrupt> EndpointRead<EpType>
Sourcepub fn new(endpoint: Endpoint<EpType, In>, transfer_size: usize) -> Self
pub fn new(endpoint: Endpoint<EpType, In>, transfer_size: usize) -> Self
Create a new EndpointRead
wrapping the given endpoint.
The transfer_size
parameter is the size of the buffer passed to the OS
for each transfer. It will be rounded up to the next multiple of the
endpoint’s max packet size.
Sourcepub fn set_num_transfers(&mut self, num_transfers: usize)
pub fn set_num_transfers(&mut self, num_transfers: usize)
Set the number of concurrent transfers.
A value of 1 (default) means that transfers will only be submitted when
calling read()
or fill_buf()
and the buffer is empty. To maximize
throughput, a value of 2 or more is recommended for applications that
stream data continuously so that the host controller can continue to
receive data while the application processes the data from a completed
transfer.
A value of 0 means no further transfers will be submitted. Existing
transfers will complete normally, and subsequent calls to read()
and
fill_buf()
will return zero bytes (EOF).
This submits more transfers when increasing the number, but does not cancel transfers when decreasing it.
Sourcepub fn with_num_transfers(self, num_transfers: usize) -> Self
pub fn with_num_transfers(self, num_transfers: usize) -> Self
Set the number of concurrent transfers.
See Self::set_num_transfers (this version is for method chaining).
Sourcepub fn set_read_timeout(&mut self, timeout: Duration)
pub fn set_read_timeout(&mut self, timeout: Duration)
Set the timeout for waiting for a transfer in the blocking read
APIs.
This affects the std::io::Read
and std::io::BufRead
implementations
only, and not the async trait implementations.
When a timeout occurs, the call fails but the transfer is not cancelled and may complete later if the read is retried.
Sourcepub fn with_read_timeout(self, timeout: Duration) -> Self
pub fn with_read_timeout(self, timeout: Duration) -> Self
Set the timeout for an individual transfer for the blocking read
APIs.
See Self::set_read_timeout – this is for method chaining with EndpointWrite::new()
.
Sourcepub fn cancel_all(&mut self)
pub fn cancel_all(&mut self)
Cancel all pending transfers.
This sets num_transfers
to 0, so no further
transfers will be submitted. Any data buffered before the transfers are cancelled
can be read, and then the read methods will return 0 bytes (EOF).
Call num_transfers
with a non-zero value
to resume receiving data.
Sourcepub fn into_inner(self) -> Endpoint<EpType, In>
pub fn into_inner(self) -> Endpoint<EpType, In>
Destroy this EndpointRead
and return the underlying Endpoint
.
Any pending transfers are not cancelled.
Sourcepub fn until_short_packet(&mut self) -> EndpointReadUntilShortPacket<'_, EpType> ⓘ
pub fn until_short_packet(&mut self) -> EndpointReadUntilShortPacket<'_, EpType> ⓘ
Get an EndpointReadUntilShortPacket
adapter that will read only until
the end of a short or zero-length packet.
Some USB protocols use packets shorter than the endpoint’s max packet size
as a delimiter marking the end of a message. By default, EndpointRead
ignores packet boundaries, but this adapter allows you to observe these
delimiters.
Trait Implementations§
Source§impl<EpType: BulkOrInterrupt> AsyncBufRead for EndpointRead<EpType>
impl<EpType: BulkOrInterrupt> AsyncBufRead for EndpointRead<EpType>
Source§impl<EpType: BulkOrInterrupt> AsyncBufRead for EndpointRead<EpType>
impl<EpType: BulkOrInterrupt> AsyncBufRead for EndpointRead<EpType>
Source§impl<EpType: BulkOrInterrupt> AsyncRead for EndpointRead<EpType>
impl<EpType: BulkOrInterrupt> AsyncRead for EndpointRead<EpType>
Source§impl<EpType: BulkOrInterrupt> AsyncRead for EndpointRead<EpType>
impl<EpType: BulkOrInterrupt> AsyncRead for EndpointRead<EpType>
Source§impl<EpType: BulkOrInterrupt> BufRead for EndpointRead<EpType>
impl<EpType: BulkOrInterrupt> BufRead for EndpointRead<EpType>
Source§fn fill_buf(&mut self) -> Result<&[u8], Error>
fn fill_buf(&mut self) -> Result<&[u8], Error>
Read
methods, if empty. Read moreSource§fn consume(&mut self, len: usize)
fn consume(&mut self, len: usize)
amount
of additional bytes from the internal buffer as having been read.
Subsequent calls to read
only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)read
. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte
or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA
byte) is reached, and append
them to the provided String
buffer. Read moreSource§impl<EpType: BulkOrInterrupt> Read for EndpointRead<EpType>
impl<EpType: BulkOrInterrupt> Read for EndpointRead<EpType>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read more