Skip to main content

trillium_grpc/client/
mod.rs

1//! The client half of trillium-grpc.
2//!
3//! A generated `<Service>Client` wraps a [`trillium_client::Client`] and exposes
4//! one method per RPC. Each returns a typed, shape-specific call handle —
5//! [`UnaryConn`], [`StreamingConn`], or [`BidiConn`] — built on the
6//! [`GrpcClientConn`] engine: configure it with chainable `with_*` setters, then
7//! `.await` and/or iterate it to run the call and read the response, its initial
8//! metadata, and its `grpc-status` trailers. Per-client configuration
9//! (compression, deadlines) lives on [`ServiceClientExt`].
10
11mod conn;
12mod service_client;
13mod typed;
14
15pub use conn::{CancelHandle, GrpcClientConn};
16pub use service_client::{ServiceClient, ServiceClientExt};
17pub use typed::{BidiConn, StreamingConn, UnaryConn};
18
19/// Append a service-prefix segment to the client's base URL. Used by
20/// generated `From<trillium_client::Client>` impls so that each generated
21/// method only needs to specify its own RPC name as a relative path.
22///
23/// Mutates the base in place — `trillium_client::Client::base_mut` is
24/// clone-on-write across clones of the same client, so this doesn't leak
25/// to other holders.
26///
27/// Panics if the client has no base URL set.
28pub fn with_service_prefix(
29    mut client: trillium_client::Client,
30    prefix: &str,
31) -> trillium_client::Client {
32    let base = client
33        .base_mut()
34        .expect("trillium_client::Client must have a base url set");
35    let new_path = format!("{}/{prefix}/", base.path().trim_end_matches('/'));
36    base.set_path(&new_path);
37    client
38}