Skip to main content

Crate rustdv_macros

Crate rustdv_macros 

Source
Expand description

Proc macros (design-doc §6). Two macros only, per the governing principle — a macro is justified only where Python used runtime dynamism Rust lacks:

  • #[rustdv::test] (§6.1): registers the annotated async fn in the link-time test registry (the inventory/linkme technique, hand rolled for ELF: #[link_section] + __start_/__stop_ symbols).
  • #[derive(Component)] (§6.3): generates the ComponentNode traversal over #[component] fields (T, Option<T>, Vec<T>).

Implementation note (STATUS.md): the zero-dependency constraint rules out syn/quote, so parsing walks raw token trees and code generation goes through string formatting + .parse(). Supported grammar is deliberately narrow (plain fns, non-generic structs with named fields); unsupported shapes produce compile errors.

Attribute Macros§

test
Both front doors (design-doc §6.1, D46). Registers at link time either

Derive Macros§

Component
Generates the ComponentNode impl (design-doc §6.3, revised per R2): traversal of #[component] fields, including Option<T> and Vec<T>; names synthesized from field names. Emits no factory registration (R5) — but R5 is reversed: the factory returns in ch29, and this derive is where its registration will land. The impl is hand-writable; the derive is convenience.