paste
A Rust proc-macro for pasting identifiers together at compile time
Repository Health
Technical Analysis
paste is a small procedural macro crate from David Tolnay (dtolnay) that solves a specific gap in Rust’s macro system: built-in declarative macros can’t concatenate identifiers into a new identifier (e.g. combining Foo and Bar into FooBar) at the token level. paste provides a paste! macro block inside which special [<...>] syntax pastes together identifiers, literals, and case-converted fragments into a single new identifier usable anywhere a Rust identifier is expected — struct names, function names, module paths, and more.
It’s one of the widely-depended-upon utility crates in the Rust ecosystem (part of dtolnay’s suite of proc-macro crates alongside serde_derive-adjacent tools), commonly pulled in transitively by other macro-heavy crates that need to generate identifier names programmatically, such as deriving trait implementations across a family of similarly-named types.
What You Get
- A
paste!macro for wrapping any block of code that needs to generate new identifiers [<...>]bracket syntax for concatenating identifiers, literals, and other token fragments into one identifier- Case-conversion modifiers (e.g. snake_case, UpperCamelCase) applicable to pasted identifier segments
- Works inside macro_rules! macros, allowing declarative macros to generate identifier-dependent code they otherwise couldn’t
- no_std / no_alloc compatible, since it operates purely at the token/macro level with no runtime component
Common Use Cases
- Generating a family of similarly-named structs, functions, or trait impls from a single macro_rules! macro
- Building derive-macro-adjacent code generation where output identifiers depend on input type names
- Writing test-generation macros that need to produce uniquely named test functions per input case
- Implementing builder-pattern or wrapper-type macros that need to construct new type/method names from existing ones
Under The Hood
Architecture: paste is a proc-macro crate (proc-macro = true in Cargo.toml) whose entire logic lives in src/lib.rs (454 lines) plus supporting modules segment.rs (token-segment parsing/case-conversion, 233 lines), attr.rs (attribute-position macro handling, 164 lines), and error.rs (47 lines); it operates purely on the token stream at compile time, scanning for [<...>] bracket groups and re-emitting a single concatenated identifier token in their place, with no runtime component whatsoever.
Tech Stack: Written entirely in Rust (100%) with zero non-dev dependencies; its only dev-dependencies are a local paste-test-suite crate (tests/macros) plus rustversion and trybuild for compile-fail/UI-style macro testing, and it declares rust-version 1.31 for broad compatibility including no_std/no_alloc targets.
Code Quality: The codebase is compact (~900 lines total) and uses trybuild for snapshot-style compile testing of macro expansion output, which is the standard rigorous testing approach for proc-macro crates in the Rust ecosystem; it has been stable and widely depended-upon since 2018 with 9 contributors, though it has seen no commits since October 2024, reflecting a mature, feature-complete crate rather than active churn.
API Design: The API is a single macro (paste!) with one bracket syntax ([<...>]) to learn, following dtolnay’s characteristic minimal-surface design; because it operates entirely within existing macro_rules! or function bodies, there’s no new mental model beyond understanding how the bracket syntax maps to token concatenation.
Used by 8 apps in this directory
agentgateway
AI Development · Developer Tools
An open source AI-native proxy that secures, observes, and governs agent-to-LLM, agent-to-tool, and agent-to-agent communication through MCP, A2A, and unified LLM routing.
Bun
Developer Tools
An all-in-one JavaScript and TypeScript toolkit — one Rust-and-JavaScriptCore binary that replaces Node.js, npm, a bundler, and a test runner with faster equivalents.
Enso
Analytics · Data Engineering · Low Code Platforms
A visual and textual programming platform for data prep and analysis where the node graph and the underlying Enso code are always perfectly in sync, built by an Alteryx co-founder on a GraalVM engine.
fabro
Developer Tools · Devops
Define AI agent workflows as code graphs, route tasks across any LLM, and intervene only where it matters.
InfluxDB
Databases · Analytics
Open-source time-series database built for real-time ingest, fast SQL queries, and embedded Python automation — powered by Apache Arrow and Parquet.
Joplin
Note Taking
The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.
ParadeDB
Search · Databases · Analytics
Born out of Y Combinator's S2023 batch, ParadeDB is a Postgres extension that delivers Elasticsearch-quality BM25 search and real-time analytics without a separate search cluster to manage.
Spacedrive
File Storage · Collaboration
One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.