sim-macros
sim-macros turns an inline Rust module into a SIM library declaration. It
reads marker attributes such as #[sim_class], #[sim_constructor],
#[sim_fn], #[sim_macro], #[sim_codec], #[sim_number_domain], and
#[sim_site], validates their contracts, and generates the Lib manifest and
registration code that the runtime expects.
Most consumers pull this surface in through the SIM facade:
[]
= { = "sim-nest", = "0.1", = false, = ["core", "shape", "proc-macros"] }
Example
use ;
What #[sim_lib] reads
#[sim_class]for generated class exports.#[sim_constructor]plus one or more#[case(...)]declarations.#[sim_fn]plus one or more#[case(...)]declarations.#[sim_macro],#[sim_codec],#[sim_number_domain], and#[sim_site]marker declarations.- Optional
#[shape("...")]literals on classes and functions. - The
id,version, and optionalnative_exportentries on#[sim_lib(...)].
#[sim_lib] requires an inline module. The marker attributes are inert on their
own; they are consumed when the enclosing module is expanded.
What it generates
- A
<ModuleName>Libtype that implements::sim::kernel::Lib. - Manifest exports for classes, functions, macros, codecs, number domains, and sites declared in the module.
- Generated class wrappers, constructor wiring, and function adapters.
- Load-time registration for generated classes, functions, and macros.
- A
__SIM_LIB_EXPANSIONstring snapshot for inspection in tests. - Optional native ABI glue when
native_export = true.
What fails at compile time
- Missing or duplicate
id,version, or marker entries. - Malformed shape literals.
- A
#[sim_class]without a matching#[sim_constructor]. - Unsupported borrowed builtin arguments.
native_export = truesignatures that require generated class values where the ABI only supports scalar,String,Symbol, orExprtraffic.- Non-inline
#[sim_lib]modules.
These failures are deliberate: the crate rejects invalid library declarations at build time instead of widening the runtime contract.
Examples In Tree
crates/sim-macros/tests/ui/pass/basic-libcrates/sim-macros/tests/ui/pass/marker-surfacecrates/sim-macros/tests/ui/smoke/consumer
Docs And Validation
The crate has no recipe directory because compile-fail and compile-pass fixtures are the meaningful examples for a proc-macro surface. Rustdoc and UI tests cover the public contract.
- API docs: https://docs.rs/sim-macros
- Repository guide: https://github.com/sim-nest/sim-foundation
From the sim-foundation checkout:
RUSTDOCFLAGS="-D warnings"