Closed
Description
I have multiple threads reading from a std::fs::File
handle. The existing Read Trait for File is not so nice in this case because of the mutability&mut File
. I created the non-mutable platform independent version from the plattform specific counterparts like below.
It would be nice to have this in the standard library.
#[cfg(any(windows))]
fn load_exact_bytes_at(buffer: &mut Vec<u8>, file: &File, offset: u64) {
use std::os::windows::fs::FileExt;
let mut data_read = 0;
while data_read < buffer.len() {
data_read += file.seek_read(buffer, offset).unwrap();
}
}
#[cfg(any(unix))]
fn load_exact_bytes_at(buffer: &mut Vec<u8>, file: &File, offset: u64) {
use std::os::unix::fs::FileExt;
let mut data_read = 0;
while data_read < buffer.len() {
data_read += file.read_at(buffer, offset).unwrap();
}
}
Metadata
Metadata
Assignees
Labels
No labels