Download next.js/turbopack/crates/turbopack-env/src/embeddable.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-env/src/embeddable.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-env/src/embeddable.rs
-
curl -L -o embeddable.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-env/src/embeddable.rs
1.29 kB
| use anyhow::Result; | |
| use turbo_rcstr::RcStr; | |
| use turbo_tasks::{ResolvedVc, Vc}; | |
| use turbo_tasks_env::{EnvMap, ProcessEnv}; | |
| use turbopack_ecmascript::utils::StringifyJs; | |
| /// Encodes values as JS strings so that they can be safely injected into a JS | |
| /// output. | |
| pub struct EmbeddableProcessEnv { | |
| prior: ResolvedVc<Box<dyn ProcessEnv>>, | |
| } | |
| impl EmbeddableProcessEnv { | |
| pub fn new(prior: ResolvedVc<Box<dyn ProcessEnv>>) -> Result<Vc<Self>> { | |
| Ok(EmbeddableProcessEnv { prior }.cell()) | |
| } | |
| } | |
| impl ProcessEnv for EmbeddableProcessEnv { | |
| async fn read_all(&self) -> Result<Vc<EnvMap>> { | |
| let prior = self.prior.read_all().await?; | |
| let encoded = prior | |
| .iter() | |
| .map(|(k, v)| (k.clone(), StringifyJs(v).to_string().into())) | |
| .collect(); | |
| Ok(Vc::cell(encoded)) | |
| } | |
| async fn read(&self, name: RcStr) -> Result<Vc<Option<RcStr>>> { | |
| let prior = self.prior.read(name).await?; | |
| let encoded = prior | |
| .as_deref() | |
| .map(|s| StringifyJs(s).to_string()) | |
| .map(RcStr::from); | |
| Ok(Vc::cell(encoded)) | |
| } | |
| } | |