turbopack_core/introspect/
output_asset.rs

1use anyhow::Result;
2use turbo_rcstr::{RcStr, rcstr};
3use turbo_tasks::{ResolvedVc, ValueToString, Vc};
4
5use super::{
6    Introspectable, IntrospectableChildren,
7    utils::{children_from_output_assets, content_to_details},
8};
9use crate::{
10    asset::Asset,
11    output::{OutputAsset, OutputAssetsReference},
12};
13
14#[turbo_tasks::value]
15pub struct IntrospectableOutputAsset(ResolvedVc<Box<dyn OutputAsset>>);
16
17#[turbo_tasks::value_impl]
18impl IntrospectableOutputAsset {
19    #[turbo_tasks::function]
20    pub fn new(asset: ResolvedVc<Box<dyn OutputAsset>>) -> Result<Vc<Box<dyn Introspectable>>> {
21        Ok(
22            *ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(asset).unwrap_or_else(|| {
23                ResolvedVc::upcast(IntrospectableOutputAsset(asset).resolved_cell())
24            }),
25        )
26    }
27}
28
29#[turbo_tasks::value_impl]
30impl Introspectable for IntrospectableOutputAsset {
31    #[turbo_tasks::function]
32    fn ty(&self) -> Vc<RcStr> {
33        Vc::cell(rcstr!("output asset"))
34    }
35
36    #[turbo_tasks::function]
37    fn title(&self) -> Vc<RcStr> {
38        self.0.path().to_string()
39    }
40
41    #[turbo_tasks::function]
42    fn details(&self) -> Vc<RcStr> {
43        content_to_details(self.0.content())
44    }
45
46    #[turbo_tasks::function]
47    fn children(&self) -> Vc<IntrospectableChildren> {
48        children_from_output_assets(self.0.references())
49    }
50}