taut_rpc/lib.rs
1//! # taut-rpc
2//!
3//! End-to-end type-safe RPC between a Rust/axum server and a TypeScript client.
4//!
5//! `taut-rpc` makes Rust types the single source of truth for an HTTP/SSE/WebSocket
6//! API: a procedural macro records each procedure's signature into an intermediate
7//! representation (IR), and a separate codegen step turns that IR into a static
8//! `.ts` client. Changing a Rust signature surfaces as a TypeScript compile error
9//! at the call site, with no runtime schema fetch on boot.
10//!
11//! This crate provides the public runtime API: the [`Router`] used to mount
12//! procedures onto an `axum::Router`, the [`TautError`] trait that constrains
13//! procedure error types, and the [`Validate`] bridge for input/output validation.
14//!
15//! ## v0.1 features
16//!
17//! - **Validation** (Phase 4): the [`Validate`] derive macro and [`validate`]
18//! module provide declarative input/output validation. Constraints are
19//! declared with `#[validate(...)]` attributes and emitted into the IR so
20//! the generated TypeScript client can mirror server-side checks. See
21//! [`validate::run`], [`validate::collect`], [`validate::nested`], and
22//! [`validate::check`] for the runtime helpers used by generated code.
23//!
24//! See [`SPEC.md`](https://github.com/anthropics/taut-rpc/blob/main/SPEC.md) for
25//! the full design — wire format, type mapping, IR schema, and versioning rules.
26//! The [`IR_VERSION`] constant tracks SPEC §9.
27//!
28//! For ergonomic imports use `use taut_rpc::prelude::*;` — see [`prelude`].
29
30#![warn(missing_docs)]
31
32pub mod prelude;
33
34pub mod dump;
35pub mod error;
36pub mod ir;
37pub mod procedure;
38pub mod router;
39pub mod type_map;
40pub mod types;
41pub mod validate;
42pub mod wire;
43
44pub use dump::{dump_if_requested, ir_json};
45pub use error::{StandardError, TautError};
46pub use procedure::{
47 ProcedureBody, ProcedureDescriptor, ProcedureHandler, ProcedureResult, StreamFrame,
48 StreamHandler, UnaryHandler,
49};
50pub use router::{ProcKindRuntime, Router};
51pub use types::TautType;
52pub use validate::{Constraint, Validate, ValidationError};
53
54pub use taut_rpc_macros::{rpc, TautError, Type, Validate};
55
56/// Current IR schema version. Tracks SPEC §9 — codegen rejects mismatches.
57pub const IR_VERSION: u32 = 1;