Expand description
Zero-dependency derive macros for nextjson.
Implemented entirely with the standard proc_macro API: no syn, no
quote, no proc-macro2. The input TokenStream is parsed by a
hand-written recursive-descent parser into a small AST, and the output is
generated as text and re-parsed.
§Forward compatibility contract
A derive macro only ever receives a single item’s tokens, and this parser
interprets a deliberately stable grammar subset: the item header
(struct / enum + name), the generic parameter list, the where
clause, and the field / variant structure, plus #[njson] /
#[nextjson] / #[serde] attributes. Everything inside a field or
generic type position is carried through verbatim as an opaque token
sequence, so new Rust syntax that appears in type positions (new
literals, impl Trait forms, associated-type paths, …) needs no parser
change — it is round-tripped unchanged.
The risk of future item-level grammar changes is handled defensively:
parse_input requires that every input token be consumed. If a future
Rust release extends item syntax in a way this parser does not understand,
the macro fails with a loud compile_error! naming the leftover tokens
instead of silently generating impls from a mis-parsed subset.
Derive Macros§
- Nson
Deserialize - Derive NextJson’s native decoding contract.
- Nson
Serialize - Derive NextJson’s native serialization contract and compile-time schema.