use anyhow::Result; use turbo_tasks::{FxIndexSet, ResolvedVc, Vc}; use turbo_tasks_fs::FileSystemPath; use crate::asset::Asset; #[turbo_tasks::value(transparent)] pub struct OptionOutputAsset(Option>>); /// An asset that should be outputted, e. g. written to disk or served from a /// server. #[turbo_tasks::value_trait] pub trait OutputAsset: Asset { /// The identifier of the [OutputAsset]. It's expected to be unique and /// capture all properties of the [OutputAsset]. #[turbo_tasks::function] fn path(&self) -> Vc; /// Other references [OutputAsset]s from this [OutputAsset]. #[turbo_tasks::function] fn references(self: Vc) -> Vc { OutputAssets::empty() } #[turbo_tasks::function] fn size_bytes(self: Vc) -> Vc> { Vc::cell(None) } } #[turbo_tasks::value(transparent)] pub struct OutputAssets(Vec>>); #[turbo_tasks::value_impl] impl OutputAssets { #[turbo_tasks::function] pub fn new(assets: Vec>>) -> Vc { Vc::cell(assets) } #[turbo_tasks::function] pub async fn concatenate(&self, other: Vc) -> Result> { let mut assets: FxIndexSet<_> = self.0.iter().copied().collect(); assets.extend(other.await?.iter().copied()); Ok(Vc::cell(assets.into_iter().collect())) } } impl OutputAssets { pub fn empty() -> Vc { Self::new(vec![]) } pub fn empty_resolved() -> ResolvedVc { ResolvedVc::cell(vec![]) } } /// A set of [OutputAsset]s #[turbo_tasks::value(transparent)] pub struct OutputAssetsSet(FxIndexSet>>); // TODO All Vc::try_resolve_downcast::> calls should be // removed