turbopack_core/source.rs
1use turbo_rcstr::RcStr;
2use turbo_tasks::{ResolvedVc, Vc};
3
4use crate::{asset::Asset, ident::AssetIdent};
5
6/// Unparsed input source code. Source code is processed into [`Module`]s by the [`AssetContext`].
7/// All `Source`s have content and an identifier.
8///
9/// For documentation about where this is used and how it fits into the rest of Turbopack, see
10/// [`crate::_layers`].
11///
12/// [`Module`]: crate::module::Module
13/// [`AssetContext`]: crate::context::AssetContext
14#[turbo_tasks::value_trait]
15pub trait Source: Asset {
16 /// The identifier of the [Source]. It's expected to be unique and capture
17 /// all properties of the [Source].
18 #[turbo_tasks::function]
19 fn ident(&self) -> Vc<AssetIdent>;
20
21 /// A human-readable description of this source, explaining where the code
22 /// comes from. For sources that transform another source, this should
23 /// include the inner source's description, creating a readable chain
24 /// like `"loaders [sass-loader] transform of file content of
25 /// ./styles.scss"`.
26 #[turbo_tasks::function]
27 fn description(&self) -> Vc<RcStr>;
28}
29
30#[turbo_tasks::value(transparent)]
31pub struct OptionSource(Option<ResolvedVc<Box<dyn Source>>>);
32
33#[turbo_tasks::value(transparent)]
34pub struct Sources(Vec<ResolvedVc<Box<dyn Source>>>);