Skip to main content

tonin_client/
lib.rs

1//! Tiny peer-service client primitives. No server-framework deps.
2//!
3//! # When to use
4//!
5//! Service B calls Service A — pull this in, **not** [`tonin-core`],
6//! which drags the tonic server stack, OTLP telemetry SDK, MCP sidecar
7//! runtime, JWT validation and JWKS fetching along with it. This crate
8//! holds only the contract pieces a caller actually needs: auth context,
9//! retry/breaker config, and W3C trace propagation.
10//!
11//! # Example
12//!
13//! Propagate an inbound `AuthCtx` + `traceparent` onto an outbound tonic
14//! request:
15//!
16//! ```rust,no_run
17//! use tonin_client::{AuthCtx, propagate};
18//! use tonic::Request;
19//!
20//! fn forward(inbound: &Request<()>) -> Request<()> {
21//!     let caller = AuthCtx::from(inbound);
22//!     let mut outbound = Request::new(());
23//!     caller.propagate(&mut outbound);
24//!     propagate::inject_traceparent(
25//!         &mut outbound,
26//!         "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
27//!     );
28//!     outbound
29//! }
30//! ```
31//!
32//! # Modules
33//!
34//! - [`auth`] — `AuthCtx`, `RawToken`, `PrincipalKind`, `AuthError`.
35//! - [`retry`] — `RetryPolicy`, `Backoff`, `RetryableCodes`.
36//! - [`breaker`] — `CircuitBreaker` config with three-state presets.
37//! - [`propagate`] — W3C `traceparent` / `tracestate` injection.
38//!
39//! # Sample app
40//!
41//! <https://github.com/Rushit/tonin/tree/main/examples/greeter> —
42//! Service B in the demo depends on this crate to call Service A.
43//!
44//! # Sibling crates
45//!
46//! - <https://docs.rs/tonin> — umbrella crate for service authors.
47//! - <https://docs.rs/tonin-core> — server runtime (use on the
48//!   service being called, not on the caller).
49//!
50//! [`tonin-core`]: https://docs.rs/tonin-core
51
52pub mod auth;
53pub mod breaker;
54pub mod propagate;
55pub mod retry;
56
57pub use auth::{AuthCtx, AuthError, PrincipalKind, RawToken};