rorpc-macros
Procedural macro bridge for rorpc — thin wrappers over rorpc-parse.
Overview
This crate contains only proc-macro entry points. All parsing, validation, and code generation logic lives in rorpc-parse where it can be tested with normal #[test] functions.
The entire implementation is a single lib.rs file with five proc macros that delegate to rorpc-parse.
Macros
#[contract]
Automatically generate TypeScript contract before fn main() runs (debug builds only). Replaces manual generate_contract() boilerplate.
Configure the output path in Cargo.toml:
[]
= "../client/src/rpc/bindings.ts"
async
Supported syntaxes:
#[contract]— reads[package.metadata.rorpc] client_pathfromCargo.toml#[contract("../client/bindings.ts")]— string literal path#[contract(CLIENT_PATH)]— constant#[contract(concat!(...))]— concat expression
See docs/metadata-bridge.md for setup options.
Method-Specific Shorthands
Concise syntax for common HTTP methods:
use ;
async
async
Available methods: get, post, put, patch, delete
Optional attributes:
data— SSE data payload type for streaming handlers (e.g.data = "StreamEvent")
#[rorpc::route]
Explicit method + path syntax:
async
Required attributes:
method— HTTP method ("GET","POST", etc.)path— Route path (e.g."/planet/list")
Optional attributes:
data— SSE data payload type for streaming handlers
router!
Auto-discovery macro that builds an Axum Router from all annotated handlers using the inventory crate.
use router;
// All handlers, no state
let app = router!;
// With state
let app = router!;
// Module filtering
let app = router!;
let app = router!;
let app = router!; // brace expansion
let app = router!; // wildcard
// Filtering + state (any order)
let app = router!;
let app = router!;
#[derive(ZodTs)]
Generate a fn zod_ts() -> String method that returns TypeScript Zod schemas. The generated schema is registered via inventory for contract generation.
use ZodTs;
use ;
Supported #[zod(...)] attributes:
- Strings:
min_length(n),max_length(n),length(n),email,url,regex("pattern"),starts_with("s"),ends_with("s"),includes("s") - Numbers:
min(n),max(n),int,positive,negative,nonnegative,nonpositive,finite - Arrays:
min_length(n),max_length(n),length(n)
#[derive(OrpcErrors)]
Register error enum variants for TypeScript contract generation. Variant names are converted to SCREAMING_SNAKE_CASE.
use OrpcErrors;
Installation
This crate is typically used via the rorpc facade crate:
[]
= "0.1"
Or add it directly (not recommended):
[]
= "0.1"
Architecture
rorpc-macros (proc-macro bridge, lib.rs only)
└── rorpc-parse (all implementation, fully testable)
└── syn 3.0, quote, proc-macro2, inventory
Why the split?
- Proc-macro crates can't have normal
#[test]functions - All logic in
rorpc-parsecan be unit-tested rorpc-macrosis just thinTokenStreamconversion wrappers