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