turbopack_core/introspect/
source.rs1use anyhow::Result;
2use turbo_rcstr::RcStr;
3use turbo_tasks::{ResolvedVc, ValueToString, Vc};
4
5use super::{Introspectable, utils::content_to_details};
6use crate::{asset::Asset, source::Source};
7
8#[turbo_tasks::value]
9pub struct IntrospectableSource(ResolvedVc<Box<dyn Source>>);
10
11#[turbo_tasks::value_impl]
12impl IntrospectableSource {
13 #[turbo_tasks::function]
14 pub async fn new(asset: ResolvedVc<Box<dyn Source>>) -> Result<Vc<Box<dyn Introspectable>>> {
15 Ok(*ResolvedVc::try_sidecast::<Box<dyn Introspectable>>(asset)
16 .unwrap_or_else(|| ResolvedVc::upcast(IntrospectableSource(asset).resolved_cell())))
17 }
18}
19
20#[turbo_tasks::function]
21fn ty() -> Vc<RcStr> {
22 Vc::cell("source".into())
23}
24
25#[turbo_tasks::value_impl]
26impl Introspectable for IntrospectableSource {
27 #[turbo_tasks::function]
28 fn ty(&self) -> Vc<RcStr> {
29 ty()
30 }
31
32 #[turbo_tasks::function]
33 fn title(&self) -> Vc<RcStr> {
34 self.0.ident().to_string()
35 }
36
37 #[turbo_tasks::function]
38 fn details(&self) -> Vc<RcStr> {
39 content_to_details(self.0.content())
40 }
41}