[−][src]Function dia_files::read
pub fn read(
src: &mut dyn Read,
limit: Option<usize>
) -> Result<Vec<u8>, ReadError>
Reads bytes from a source
Notes
- If data to be read exceeds limit, an error is returned. If you don't care about exceeding data, you can pass
Read::take()
to this function. - Source will be used as-is, without any wrapper. So you might want to use
BufReader
. - Internal buffer is 8 KiB, it might be changed in the future.
Errors
While reading from source, if any error raises, it will be returned along with read data (see ReadError
).
Examples
use std::io; fn test() -> io::Result<()> { let data = b"hi there"; assert_eq!( &data[..], dia_files::read(&mut &data[..], None)?.as_slice(), ); assert_eq!( &data[..], dia_files::read(&mut &data[..], Some(data.len()))?.as_slice(), ); let err = dia_files::read(&mut &data[..], Some(0)).unwrap_err(); // We don't know how much data is read let read_data = err.data().unwrap(); assert_eq!(read_data, &data[..read_data.len()]); Ok(()) } test().unwrap();