You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
879 B
41 lines
879 B
use super::*;
|
|
use job::Job;
|
|
use std::io::{self, Read};
|
|
use std::fmt;
|
|
|
|
pub fn work_on(job: &mut Job) -> io::Result<usize>
|
|
{
|
|
let output = job.output_slice();
|
|
let output = unsafe {
|
|
// SAFETY: Required because the compiler thinks we're mutably borrowing the same data later on, even though they are unrelated fields of the struct
|
|
std::slice::from_raw_parts_mut(output.as_mut_ptr(), output.len())
|
|
};
|
|
|
|
let mut read=0;
|
|
while read < job.len() {
|
|
match job.read(&mut output[read..])? {
|
|
0 => break,
|
|
current => read+=current,
|
|
}
|
|
}
|
|
Ok(read)
|
|
}
|
|
|
|
pub fn output_if_able<T, D>(ar: &mut T)
|
|
where T: AsMut<[job::Status<D>]> + ?Sized,
|
|
D: fmt::Display
|
|
{
|
|
let slice = ar.as_mut();
|
|
for item in slice.iter_mut()
|
|
{
|
|
if item.is_pending() {
|
|
return
|
|
} else {
|
|
if let Some(item) = item.take() {
|
|
println!("{}", item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|