work r/w loop okey

serial
Avril 4 years ago
parent 8b996f5698
commit d623b34f7f
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -8,6 +8,8 @@ mod work;
mod consts; mod consts;
pub const BUFSIZE: usize = 4096; // 4kb
fn main() { fn main() {
println!("Hello, world!"); println!("Hello, world!");
} }

@ -2,12 +2,19 @@ use super::*;
use job::Job; use job::Job;
use std::io::Read; use std::io::Read;
pub fn work_on(job: &mut Job) -> Result<(), Box<dyn std::error::Error>> pub fn work_on(job: &mut Job) -> Result<usize, Box<dyn std::error::Error>>
{ {
let output = job.output_slice(); let output = job.output_slice();
let mut buf = [0u8; 4096]; let output = unsafe {
while let Ok(read) = job.read(&mut buf) { // Required because the compiler thinks we're mutably borrowing the same data later on, even though they are unrelated fields of the struct
//TODO: copy from `job`'s file into `output`. std::slice::from_raw_parts_mut(output.as_mut_ptr(), output.len())
};
let mut read=0;
loop {
match job.read(&mut output[read..])? {
0 => break,
current => read+=current,
} }
todo!() }
Ok(read)
} }

Loading…
Cancel
Save