pub fn buffered_reader_generic_read_impl<T: BufferedReader<C>, C: Debug + Sync + Send>(
bio: &mut T,
buf: &mut [u8]
) -> Result<usize, Error>
Expand description
A generic implementation of std::io::Read::read
appropriate for
any BufferedReader
implementation.
This function implements the std::io::Read::read
method in terms
of the data_consume
method. We can’t use the io::std::Read
interface, because the BufferedReader
may have buffered some
data internally (in which case a read will not return the buffered
data, but the following data).
This implementation is generic. When deriving a BufferedReader
,
you can include the following:
impl<'a, T: BufferedReader> std::io::Read for XXX<'a, T> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
return buffered_reader_generic_read_impl(self, buf);
}
}
It would be nice if we could do:
impl <T: BufferedReader> std::io::Read for T { ... }
but, alas, Rust doesn’t like that (“error[E0119]: conflicting
implementations of trait std::io::Read
for type &mut _
”).