syn

A Rust parsing library that turns a stream of Rust tokens into a full syntax tree for procedural macros.

Library
Cargo
v3.0.6
3,426 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
91 /100 Excellent
Development Activity 96
Maintenance 96
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
93 /100 Excellent
Architecture 95
Code Quality 95
Innovation 92
Learning Curve 70

Syn is the foundational parsing library of the Rust procedural-macro ecosystem. It takes a stream of Rust tokens and parses it into a rich, typed syntax tree that can represent nearly all stable Rust source code plus some unstable syntax, rooted at entry points like File, Item, Expr, and Type.

Built around parser functions with the signature fn(ParseStream) -> Result<T>, Syn lets macro authors parse derive inputs, attributes, and entirely custom syntaxes while preserving Span location information for precise, user-friendly compiler error messages. Its aggressive feature gating keeps compile times low by pulling in only the functionality a given macro actually needs.

What You Get

  • A complete typed syntax tree for Rust source, rooted at File, Item, Expr, Type, and DeriveInput.
  • A Parse trait and ParseStream API for building parsers for derive inputs, attributes, and fully custom syntaxes.
  • Span-aware error reporting so macros can point compiler errors at the exact offending token.
  • Optional visit, visit-mut, and fold traversal traits, plus printing back to token streams via quote.
  • Fine-grained Cargo feature flags (derive, full, parsing, printing, and more) to minimize compile-time cost.

Common Use Cases

  • Parsing DeriveInput inside a #[proc_macro_derive] to generate trait implementations.
  • Reading and validating attribute arguments in attribute-like procedural macros.
  • Implementing function-like macros with bespoke DSL syntax via custom Parse impls.
  • Statically analyzing or transforming Rust source in build scripts and tooling.

Under The Hood

Architecture Syn is organized as one crate whose ~50 source modules (src/expr.rs, src/item.rs, src/ty.rs, src/pat.rs, src/generics.rs, and peers) each define the syntax-tree types and Parse impls for one region of the Rust grammar. Parsing flows from a proc_macro2::TokenStream through src/buffer.rs’s cheaply copyable Cursor into the ParseStream/ParseBuffer machinery in src/parse.rs, which drives per-node fn(ParseStream) -> Result<T> parsers; src/lookahead.rs and src/precedence.rs handle disambiguation and expression precedence. A large body of repetitive trait code (Clone, Debug, Eq, Hash, Visit, VisitMut, Fold) is machine-generated by the codegen/ tool from the syn.json grammar description and checked in under src/gen/.

Tech Stack Pure Rust (edition 2021, minimum rustc 1.71) with a deliberately tiny dependency set: proc-macro2 for the token shim, optional quote for the printing feature, and unicode-ident for identifier validation. Behavior is sliced across fine-grained Cargo features (derive, full, parsing, printing, visit, visit-mut, fold, clone-impls, extra-traits, proc-macro) so callers compile only what they use. A build.rs handles rustc version detection.

Code Quality Maturity and rigor are high: 27 integration test files under tests/ (snapshot tests via insta, regression suites, and a corpus test that parses real crates from crates.io), fuzz targets under fuzz/, and benchmarks under benches/. Error handling is threaded consistently through the crate’s own syn::Error/Result types with span attribution, and the generated-vs-handwritten split keeps the mechanical trait impls consistent across hundreds of node types.

API Design The public API is the de-facto standard for the Rust macro ecosystem, which is itself strong evidence of its ergonomics. The Parse trait plus parse_macro_input! reduces a derive macro to a few lines, while ParseStream combinators make custom syntaxes approachable. Documentation is thorough — extensive rustdoc on lib.rs, worked examples/ (heapsize, lazy-static, dump-syntax, trace-var), and a companion proc-macro workshop. The main learning curve is the breadth of node types and the feature-flag matrix rather than any inconsistency in the API surface.

Used by 29 apps in this directory

Rust
65%
Apache 2.0

agentgateway

AI Development · Developer Tools · Mcp

5,071

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.

View details
88
Repo Health
82
Technical
69
Dependency
Built with
Rust 65%
Go 23%
Updated 5 days ago
TypeScript
54%
MIT

Anarlog

AI Assistants · Note Taking · Productivity

9,404

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
68
Dependency
Built with
TypeScript 54%
Rust 34%
Updated 4 days ago
Dart
74%
AGPL 3.0

AppFlowy

AI Assistants · Collaboration · Productivity

76,967

The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.

View details
66
Repo Health
81
Technical
67
Dependency
Built with
Dart 74%
Rust 24%
Updated 1 weeks ago
Rust
67%
MIT

Bun

Developer Tools

96,068

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.

View details
92
Repo Health
91
Technical
64
Dependency
Built with
Rust 67%
C++ 19%
TypeScript 10%
Updated 5 days ago
Rust
52%
Apache 2.0

cocoindex

AI Development · Data Engineering

11,607

An incremental data indexing engine that keeps AI agent context perpetually fresh by reprocessing only what changed.

View details
87
Repo Health
85
Technical
65
Dependency
Built with
Rust 52%
Python 48%
Updated 4 days ago
Rust
95%
Other

Databend

Data Engineering · Databases

9,452

Open-source enterprise data warehouse unifying analytics, vector search, full-text search, and AI agent orchestration in a single Rust-built engine on S3.

View details
93
Repo Health
84
Technical
77
Dependency
Built with
Rust 95%
Updated 4 days ago
Rust
67%
Other

DefGuard

Authentication · Networking · Security

2,849

Self-hosted secure remote access that unifies WireGuard VPN, identity management, and connection-level MFA in one open-source platform.

View details
84
Repo Health
82
Technical
72
Dependency
Built with
Rust 67%
TypeScript 31%
Updated 1 weeks ago
Rust
80%
MIT

fabro

Developer Tools · Devops

1,658

Define AI agent workflows as code graphs, route tasks across any LLM, and intervene only where it matters.

View details
82
Repo Health
83
Technical
67
Dependency
Built with
Rust 80%
TypeScript 15%
Updated 5 days ago
Rust
88%
GPL 2.0

Fresh

Code Editors · Developer Tools

9,052

A zero-configuration terminal text editor with familiar keybindings, full mouse support, LSP-powered IDE features, and a built-in orchestrator for running multiple coding agents in parallel worktrees.

View details
86
Repo Health
88
Technical
71
Dependency
Built with
Rust 88%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers