define and use BufferedReader trait

This commit is contained in:
Dietmar Maurer
2019-01-05 17:28:20 +01:00
parent 1006acd626
commit 0a72e26704
2 changed files with 26 additions and 13 deletions

View File

@ -17,6 +17,15 @@ use std::os::unix::io::AsRawFd;
pub mod timer;
/// The `BufferedReader` trait provides a single function
/// `buffered_read`. It returns a reference to an internal buffer. The
/// purpose of this traid is to avoid unnecessary data copies.
pub trait BufferedReader {
/// This functions tries to fill the internal buffers, then returns
/// a reference to the available data.
fn buffered_read(&mut self, offset: u64) -> Result<&[u8], Error>;
}
/// Directly map a type into a binary buffer. This is mostly useful
/// for reading structured data from a byte stream (file). You need to
/// make sure that the buffer location does not change, so please