use std::marker::PhantomData; use anyhow::Result; use crate::{RawVc, Vc}; /// Trait to implement in order for a type to be accepted as a /// `turbo_tasks::function` return type. pub trait TaskOutput: Send { type Return: ?Sized; fn try_from_raw_vc(raw_vc: RawVc) -> Vc { Vc { node: raw_vc, _t: PhantomData, } } fn try_into_raw_vc(self) -> Result; } impl TaskOutput for Vc where T: Send + ?Sized, { type Return = T; fn try_into_raw_vc(self) -> Result { Ok(self.node) } } impl TaskOutput for () { type Return = (); fn try_into_raw_vc(self) -> Result { let unit = Vc::<()>::default(); Ok(unit.node) } } impl TaskOutput for Result where T: TaskOutput, { type Return = T::Return; fn try_into_raw_vc(self) -> Result { self?.try_into_raw_vc() } }