4 ms·
For those who don’t know, much of Serde’s magic is powered by Rust procedural derive macros, which generate (i.e. “derive”) code from a Rust struct definition.
by trevyn 5y ago
For those who don’t know, much of Serde’s magic is powered by Rust procedural derive macros, which generate (i.e. “derive”) code from a Rust struct definition.
You can, of course, write your own derive macros, and apply several derive macros to a single struct.
I wrote some to derive SQLite schemas and migrations and queries and auto-generate frontend TypeScript RPC code. So my source of truth is the Rust struct, and that sort of magically generates everything else.
I don’t know if this is a good idea, but it’s been pretty fun so far. :-)
There are also derive-macro-powered crates to do GraphQL, other flavors of SQL, WASM bindings, etc etc.