rorpc-parse
AST parsing utilities and code generation for rorpc proc macros.
Overview
This is a regular (non-proc-macro) library containing all the parsing, validation, and code generation logic for the rorpc ecosystem. By extracting implementation from the proc-macro crate, everything becomes testable with normal #[test] functions.
The rorpc-macros crate is a thin bridge that calls functions from this crate.
Architecture
rorpc-macros (proc-macro bridge, lib.rs only)
└── rorpc-parse (this crate — all implementation)
└── syn 3.0, quote, proc-macro2, inventory
Module Structure
errors— StructuredErrortype with span information and compile-time suggestionstypes— AST-based wrapper extraction (Json<T>,Result<T,E>,Option<T>, etc.)attributes—#[serde(...)]and#[zod(...)]attribute parsingfunctions— Handler function signature analysis →HandlerSignaturecodegen— Code generation; each sub-module corresponds to one proc macro:orpc.rs—#[rorpc]attribute macro expansionrouter.rs—router!macro expansionzod_ts.rs—#[derive(ZodTs)]expansionerror_derive.rs—#[derive(OrpcErrors)]expansion
Features
AST-Based Type Matching
No fragile string comparisons. All wrapper extraction uses AST path segment identifiers:
use ;
// Works for: Json<T>, axum::Json<T>, axum::extract::Json<T>, etc.
if let Some = try_extract_wrapper
// Works for: Result<T, E>, std::result::Result<T, E>, core::result::Result<T, E>
if let Some = try_extract_wrapper
Structured Error Types
Compile-time diagnostics with span-accurate errors and actionable suggestions:
use ;
new
Error kinds:
MissingWrapper— ExpectedJson<T>, found plain typeEmptyGenericArgs— Wrapper has no generic argumentsUnsupportedType— Type not supported in current contextInvalidAttrValue— Attribute value doesn't match expected formatMissingRequiredAttr— Required attribute is missingConflictingAttrs— Two attributes can't be used togetherMissingReturnType— Function missing return typeInvalidHandlerSig— Handler signature doesn't match expected patternUnknownKey— Unknown key in attributeSynError— Wrappedsyn::Error
Handler Signature Analysis
Extracts and validates Axum handler signatures:
use ;
let sig = extract_handler_signature?;
// HandlerSignature {
// fn_name: "list_planets",
// state_type: Some(Type::Path("Db")),
// input_type: None,
// output_type: Type::Path("Vec<Planet>"),
// error_type: Some(Type::Path("AppError")),
// is_streaming: false,
// is_async: true,
// }
Attribute Parsing
Dual syntax support for #[zod(...)] constraints:
// key = value
// key(value)
Runtime Type Conversion Utilities
String-based type-to-Zod conversion for runtime contract generation (shared with the rorpc crate):
use ;
use ;
assert_eq!;
assert_eq!;
assert!;
assert!;
Testing
64+ unit tests covering:
- Wrapper extraction with various path forms
- Error type construction and messages
- Attribute parsing (both syntaxes)
- Handler signature validation
- Runtime type-to-Zod conversion
- Edge cases (empty generics, nested types, etc.)
Dependencies
- syn 3.0 — AST parsing (with
full,parsing,extra-traitsfeatures) - quote — Code generation
- proc-macro2 — Token stream manipulation
- inventory — Compile-time registration system
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.