use crate::{ResolvedVc, TaskInput, Vc}; // NOTE: If you add new implementations of this trait, you'll need to modify // `expand_task_input_type` in `turbo-tasks-macros/src/func.rs`. pub trait FromTaskInput: private::Sealed { type TaskInput: TaskInput; fn from_task_input(from: Self::TaskInput) -> Self; } mod private { use super::*; /// Implements the sealed trait pattern: /// pub trait Sealed {} impl Sealed for ResolvedVc where T: ?Sized {} impl Sealed for Vec where T: FromTaskInput {} impl Sealed for Option where T: FromTaskInput {} } impl FromTaskInput for ResolvedVc where T: Send + Sync + ?Sized, { type TaskInput = Vc; fn from_task_input(from: Vc) -> ResolvedVc { debug_assert!( from.is_resolved(), "Outer `Vc`s are always resolved before this is called" ); ResolvedVc { node: from } } } impl FromTaskInput for Vec where T: FromTaskInput, { type TaskInput = Vec; fn from_task_input(from: Vec) -> Vec { let mut converted = Vec::with_capacity(from.len()); for value in from { converted.push(T::from_task_input(value)); } converted } } impl FromTaskInput for Option where T: FromTaskInput, { type TaskInput = Option; fn from_task_input(from: Option) -> Option { from.map(T::from_task_input) } }