turbopack_core/introspect/
output_asset.rs1use anyhow::Result;
2use turbo_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 async fn new(
18 asset: ResolvedVc<Box<dyn OutputAsset>>,
19 ) -> Result<Vc<Box<dyn Introspectable>>> {
20 Ok(
21 *ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(asset).unwrap_or_else(|| {
22 ResolvedVc::upcast(IntrospectableOutputAsset(asset).resolved_cell())
23 }),
24 )
25 }
26}
27
28#[turbo_tasks::function]
29fn ty() -> Vc<RcStr> {
30 Vc::cell("output asset".into())
31}
32
33#[turbo_tasks::value_impl]
34impl Introspectable for IntrospectableOutputAsset {
35 #[turbo_tasks::function]
36 fn ty(&self) -> Vc<RcStr> {
37 ty()
38 }
39
40 #[turbo_tasks::function]
41 fn title(&self) -> Vc<RcStr> {
42 self.0.path().to_string()
43 }
44
45 #[turbo_tasks::function]
46 fn details(&self) -> Vc<RcStr> {
47 content_to_details(self.0.content())
48 }
49
50 #[turbo_tasks::function]
51 fn children(&self) -> Vc<IntrospectableChildren> {
52 children_from_output_assets(self.0.references())
53 }
54}