Download next.js/turbopack/crates/turbopack-wasm/src/source.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-wasm/src/source.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-wasm/src/source.rs
-
curl -L -o source.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-wasm/src/source.rs
2.27 kB
| use anyhow::Result; | |
| use serde::{Deserialize, Serialize}; | |
| use turbo_tasks::{NonLocalValue, ResolvedVc, TaskInput, Vc, trace::TraceRawVcs}; | |
| use turbo_tasks_fs::{File, FileContent}; | |
| use turbopack_core::{ | |
| asset::{Asset, AssetContent}, | |
| ident::AssetIdent, | |
| source::Source, | |
| }; | |
| pub enum WebAssemblySourceType { | |
| /// Binary WebAssembly files (.wasm). | |
| Binary, | |
| /// WebAssembly text format (.wat). | |
| Text, | |
| } | |
| /// Returns the raw binary WebAssembly source or the assembled version of a text | |
| /// format source. | |
| pub struct WebAssemblySource { | |
| source: ResolvedVc<Box<dyn Source>>, | |
| source_ty: WebAssemblySourceType, | |
| } | |
| impl WebAssemblySource { | |
| pub fn new(source: ResolvedVc<Box<dyn Source>>, source_ty: WebAssemblySourceType) -> Vc<Self> { | |
| Self::cell(WebAssemblySource { source, source_ty }) | |
| } | |
| } | |
| impl Source for WebAssemblySource { | |
| async fn ident(&self) -> Result<Vc<AssetIdent>> { | |
| Ok(match self.source_ty { | |
| WebAssemblySourceType::Binary => self.source.ident(), | |
| WebAssemblySourceType::Text => self | |
| .source | |
| .ident() | |
| .with_path(self.source.ident().path().await?.append("_.wasm")?), | |
| }) | |
| } | |
| } | |
| impl Asset for WebAssemblySource { | |
| async fn content(&self) -> Result<Vc<AssetContent>> { | |
| let content = match self.source_ty { | |
| WebAssemblySourceType::Binary => return Ok(self.source.content()), | |
| WebAssemblySourceType::Text => self.source.content(), | |
| }; | |
| let content = content.file_content().await?; | |
| let FileContent::Content(file) = &*content else { | |
| return Ok(AssetContent::file(FileContent::NotFound.cell())); | |
| }; | |
| let bytes = file.content().to_bytes(); | |
| let parsed = wat::parse_bytes(&bytes)?; | |
| Ok(AssetContent::file(File::from(&*parsed).into())) | |
| } | |
| } | |