darling
Parse attributes into structs when writing custom Rust derive macros
Repository Health
Technical Analysis
darling is a Rust crate for proc-macro authors that turns attribute parsing into a declarative, serde-like experience. Instead of hand-writing token inspection, macro authors annotate a struct and let darling read #[...] attributes into it, complete with validation and high-quality error messages.
Heavily inspired by serde in both API and internals, darling dramatically reduces the boilerplate and edge cases involved in writing robust custom derives, so proc-macros can be highly configurable with minimal effort.
What You Get
- Declarative parsing of attributes into typed structs via derive macros
- Automatic validation with clear, spanned error messages
- serde-inspired API that is familiar to Rust developers
- Support for nested attributes, defaults, and custom conversions
- Optional suggestions and diagnostics features for better UX
Common Use Cases
- Writing custom derive macros that accept configuration attributes
- Building attribute-driven code generators with minimal boilerplate
- Validating proc-macro input and surfacing helpful compiler errors
- Sharing attribute-parsing logic across a family of derive macros
Under The Hood
Architecture — darling is a Cargo workspace split into three crates: darling_core (the parsing engine and error types), darling_macro (the procedural derive implementations), and the top-level darling facade that re-exports them, so downstream users depend on a single crate. Tech Stack — Rust edition 2021 (MSRV 1.88) built on syn, quote, and proc-macro2, the standard proc-macro toolchain, with trybuild and rustversion driving compile-time tests. Code Quality — The project is mature and well-tested, with a tests/ suite, compile-fail tests via trybuild, examples, a detailed CHANGELOG, and clippy/rustfmt configuration. API Design — The derive-based API closely mirrors serde’s Deserialize, so authors declare a struct and derive FromDeriveInput/FromMeta; this makes common cases nearly free while advanced customization is available through trait implementations.