1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
use crate::task::{ContextId, GpuTask, Progress}; #[derive(Clone)] pub struct Map<T, F> { task: T, f: Option<F>, } impl<T, F> Map<T, F> { pub(crate) fn new(task: T, f: F) -> Self { Map { task, f: Some(f) } } } unsafe impl<Ec, T, F, U> GpuTask<Ec> for Map<T, F> where T: GpuTask<Ec>, F: FnOnce(T::Output) -> U, { type Output = U; fn context_id(&self) -> ContextId { self.task.context_id() } fn progress(&mut self, execution_context: &mut Ec) -> Progress<Self::Output> { self.task.progress(execution_context).map(|output| { let f = self .f .take() .expect("Cannot progress Map after it has finished."); f(output) }) } }