cratestack-macros
Procedural macros for compile-time schema processing.
Overview
cratestack-macros exposes two proc-macros that parse a .cstack file at compile time and emit Rust code inside a cratestack_schema module:
include_schema!("path.cstack")— full server surfaceinclude_client_macro!("path.cstack")— client surface only
Both are re-exported through the facade cratestack crate; consumers should depend on cratestack rather than this crate directly.
Installation
[]
= "0.2.2"
include_schema!
use include_schema;
include_schema!;
let pool = connect.await?;
let cool = builder.build;
The macro emits, inside a cratestack_schema module:
- model structs for each
model/type/enumdeclaration Create<Model>InputandUpdate<Model>Inputstructs for each model- per-model selection and include builders (
Model::select(),Model::include_selection()) - per-model filter/order helper modules (e.g.
cratestack_schema::post::published()) - the
Cratestackruntime struct withbuilder(pool),build(),bind_context(ctx),bind_auth(principal), and a per-model accessor (cool.post(),cool.user(), ...) - an
axum::model_router(cool, codec, auth_provider)constructor - a
client::Clientconstructor that wraps aCratestackClient<C> - procedure dispatch glue and
events::Subscriptionsfor@@emitmodel events - a
schema_summary()helper returning aSchemaSummaryfor tooling
The exact names depend on your schema; consult the root README for the canonical list.
include_client_macro!
Emits a strict subset of the surface above — model and input types, enums, selection/projection helpers, and the client::Client wrapper — without any SQLx or Axum integration. Use this in consumer crates that talk to a CrateStack service but do not own the database.
use include_client_macro;
include_client_macro!;
Decimal Backend
Generated code references cratestack::Decimal, which resolves at compile time to either rust_decimal::Decimal (decimal-rust-decimal, default) or the reserved decimal-bigdecimal backend.
See Also
cratestack— facade crate that re-exports both macroscratestack-parser— the parser the macros call- Quickstart
License
MIT