mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
## What
Add a `#[derive(ValueToString)]` proc macro and convert ~45 manual `ValueToString` implementations across turbopack crates to use it (-660 lines of boilerplate, 49 files touched).
## Why
Nearly every `ValueToString` impl follows the same pattern: format some fields into a string, possibly awaiting `Vc` values first. These hand-written impls are noisy boilerplate that obscure the actual format string.
## How
The derive macro generates the `#[turbo_tasks::value_impl] impl ValueToString` block automatically. A helper trait `ValueToStringify` with a blanket impl for `Display` and specializations for `Vc<T>`/`ResolvedVc<T>` handles async resolution of fields.
### Supported forms
- **No attribute** — delegates to `Display::to_string(&self)`
- `#[value_to_string("constant")]` — emits `rcstr!` directly
- `#[value_to_string("{field} text {other_field}")]` — auto-resolves named/positional fields via `ValueToStringify`
- `#[value_to_string("fmt {}", expr1, expr2)]` — explicit expressions as format args
- `#[value_to_string(expr)]` — single expression delegation
Enums support per-variant attributes (defaulting to variant name) or a single top-level attribute.
27 lines
542 B
TOML
27 lines
542 B
TOML
[package]
|
|
name = "turbo-tasks-macros"
|
|
version = "0.1.0"
|
|
description = "TBD"
|
|
license = "MIT"
|
|
edition = "2024"
|
|
|
|
[lib]
|
|
proc-macro = true
|
|
bench = false
|
|
|
|
[lints]
|
|
workspace = true
|
|
|
|
[dependencies]
|
|
either = { workspace = true }
|
|
indexmap = { workspace = true }
|
|
proc-macro-error = "1.0.4"
|
|
proc-macro2 = { workspace = true }
|
|
quote = { workspace = true }
|
|
regex = { workspace = true }
|
|
rustc-hash = { workspace = true }
|
|
syn = { workspace = true, features = ["full", "extra-traits", "visit", "visit-mut"] }
|
|
|
|
[dev-dependencies]
|
|
rstest = { workspace = true }
|