Skip to main content

connectrpc_tauri/
lib.rs

1//! ConnectRPC transport over Tauri IPC.
2//!
3//! Carries the Connect protocol over Tauri commands and channels instead of
4//! HTTP. The webview is the client; Rust hosts the services.
5//!
6//! Neither side reimplements the protocol. `ConnectRpcService` is already a
7//! `tower::Service<http::Request>`, and on the TypeScript side
8//! `@connectrpc/connect/protocol-connect` accepts any byte-level client. This
9//! crate is the shuttle between them, so framing, compression negotiation,
10//! trailers, and error mapping all come from the existing runtime.
11//!
12//! # Usage
13//!
14//! ```rust,ignore
15//! let router = Arc::new(MyService).register(connectrpc::Router::new());
16//! tauri::Builder::default()
17//!     .plugin(connectrpc_tauri::serve(ConnectRpcService::new(router)))
18//!     .run(tauri::generate_context!())?;
19//! ```
20//!
21//! # Concurrency
22//!
23//! Every IPC command is `async` and nothing in the request path blocks the
24//! runtime. The one synchronous lock guards a hash map and is never held across
25//! an await, which the `await_holding_lock` lint below enforces.
26
27// A guard held across an await would stall every other call on this app.
28#![deny(clippy::await_holding_lock)]
29
30mod body;
31mod call;
32mod codec;
33mod deferred;
34mod plugin;
35mod registry;
36mod scheme;
37
38#[cfg(feature = "testing")]
39pub mod testing;
40
41pub use deferred::DeferredDispatcher;
42pub use plugin::{PLUGIN_NAME, serve};
43pub use registry::CallId;
44pub use scheme::SCHEME;
45
46/// Generated wire types for the transport envelopes.
47///
48/// Public so tests and hand-written clients can build frames; the shapes are
49/// mirrored by `packages/transport` on the TypeScript side.
50#[allow(clippy::match_single_binding)]
51pub mod wire {
52    include!(concat!(env!("OUT_DIR"), "/connectrpc.tauri.v1.mod.rs"));
53}
54
55/// The demo service used by the tests and the example app.
56///
57/// Behind a feature flag so it does not ship in production builds of the
58/// transport.
59#[cfg(feature = "greet-example")]
60pub mod greet {
61    include!(concat!(env!("OUT_DIR"), "/greet.v1.mod.rs"));
62}