rust_grpc_lib/lib.rs
1//! Root of the `rust-grpc-lib` crate.
2//!
3//! Declares the public module tree and re-exports the proc-macro entry points
4//! from `grpc-macro` so consumers never need a direct dependency on that crate.
5//!
6//! # Modules
7//!
8//! | Module | Feature gate | Purpose |
9//! |---|---|---|
10//! | [`auth`] | `auth` (default) | JWT interceptors, validation layer, token sources |
11//! | [`build_support`] | `build` | Proto code-generation helpers for `build.rs` |
12//! | [`pool`] | always | Process-wide lazily-connected channel pool |
13//!
14//! # Re-exported macros
15//!
16//! | Item | Feature gate | What it generates |
17//! |---|---|---|
18//! | [`GrpcClient`] | `auth` (default) | `from_endpoint_with_provider` on tonic client structs |
19//! | [`GrpcNoAuthClient`] | `unauthenticated` | `from_endpoint` (no-auth) on tonic client structs |
20//! | [`keycloak_authenticated_service`] | `auth` (default) | Role-checking guards on `impl Trait for Type` blocks |
21//!
22//! See each module and the `grpc-macro` crate for full documentation.
23
24/// JWT interceptors, validation layer, and re-exports from `rust-auth-lib`.
25///
26/// Enabled by the `auth` feature (on by default). See [`auth`] for the full
27/// list of re-exported types and the two sub-modules it contains:
28/// [`auth::interceptor`] and [`auth::layer`].
29#[cfg(any(feature = "auth", doc, test))]
30pub mod auth;
31
32/// Build-time helpers for compiling the bundled `.proto` definitions into Rust.
33///
34/// Enabled by the `build` feature (off by default). The sole public entry
35/// point is [`build_support::generate_protos`], called from a consumer's
36/// `build.rs`.
37#[cfg(any(feature = "build", doc, test))]
38pub mod build_support;
39
40/// Process-wide gRPC channel pool.
41///
42/// The sole public function is [`pool::get_channel`]. Consumers do not
43/// typically call it directly — the constructors generated by [`GrpcClient`]
44/// and [`GrpcNoAuthClient`] call it internally.
45pub mod pool;
46
47/// Derive macro that generates `from_endpoint_with_provider` on a tonic client
48/// struct, wiring it into [`pool::get_channel`] with JWT auth.
49///
50/// Applied automatically by [`build_support::Config::new`] to every generated
51/// client. Re-exported here so consumers can also apply it to custom wrapper
52/// types without a direct dependency on `grpc-macro`.
53#[cfg(any(feature = "auth", doc, test))]
54pub use grpc_macro::GrpcClient;
55
56/// Derive macro that generates `from_endpoint` (no-auth) on a tonic client
57/// struct. Intended for test harnesses only; requires the `unauthenticated`
58/// feature.
59#[cfg(any(feature = "unauthenticated", doc, test))]
60pub use grpc_macro::GrpcNoAuthClient;
61
62/// Attribute macro applied to `impl Trait for Type` blocks that injects
63/// Keycloak role-checking guards into methods annotated with `#[roles(...)]`.
64///
65/// Re-exported here so consumers can write `#[rust_grpc_lib::authenticated_service]`
66/// without a direct dependency on `grpc-macro`.
67#[cfg(any(feature = "auth", doc, test))]
68pub use grpc_macro::keycloak_authenticated_service;