pub struct PluginBuilder { /* private fields */ }Expand description
Builder for the conduit Tauri v2 plugin.
Collects command registrations and configuration, then produces a
TauriPlugin via build.
Implementations§
Source§impl PluginBuilder
impl PluginBuilder
Sourcepub fn command<F>(self, name: impl Into<String>, handler: F) -> Self
pub fn command<F>(self, name: impl Into<String>, handler: F) -> Self
Register a raw command handler (Vec<u8> in, Vec<u8> out).
Command names correspond to the path segment in the
conduit://localhost/invoke/<cmd_name> URL.
Sourcepub fn handler(
self,
name: impl Into<String>,
handler: impl ConduitHandler,
) -> Self
pub fn handler( self, name: impl Into<String>, handler: impl ConduitHandler, ) -> Self
Register a #[tauri_conduit::command]-generated handler.
Works with both sync and async handlers. Sync handlers are dispatched
inline. Async handlers are spawned on the tokio runtime — truly async,
exactly like #[tauri::command].
use tauri_conduit::{command, handler};
#[command]
fn greet(name: String) -> String {
format!("Hello, {name}!")
}
#[command]
async fn fetch_user(state: State<'_, Db>, id: u64) -> Result<User, String> {
state.get_user(id).await.map_err(|e| e.to_string())
}
tauri_plugin_conduit::init()
.handler("greet", handler!(greet))
.handler("fetch_user", handler!(fetch_user))
.build()Sourcepub fn handler_raw<F>(self, name: impl Into<String>, handler: F) -> Self
pub fn handler_raw<F>(self, name: impl Into<String>, handler: F) -> Self
Register a raw closure handler (legacy API).
Accepts the same closure signature as the pre-ConduitHandler .handler():
Fn(Vec<u8>, &dyn Any) -> Result<Vec<u8>, Error>. This is a synchronous
handler dispatched via Router::register_with_context.
Use this for backward compatibility when migrating from closure-based
registration. For new code, prefer handler with
#[tauri_conduit::command] + handler!().
Sourcepub fn command_json<F, A, R>(self, name: impl Into<String>, handler: F) -> Self
pub fn command_json<F, A, R>(self, name: impl Into<String>, handler: F) -> Self
Typed JSON handler. Deserializes the request payload as A and
serializes the response as R.
Unlike Tauri’s #[tauri::command], this takes a single argument type
(not named parameters) and does not support async or State injection.
.command_json("greet", |name: String| format!("Hello, {name}!"))Sourcepub fn command_json_result<F, A, R, E>(
self,
name: impl Into<String>,
handler: F,
) -> Self
pub fn command_json_result<F, A, R, E>( self, name: impl Into<String>, handler: F, ) -> Self
Typed JSON handler that returns Result<R, E>.
Like command_json, but the handler returns
Result<R, E> where E: Display. On success, R is serialized to
JSON. On error, the error’s Display text is returned to the caller.
For Tauri-style named parameters with Result returns, prefer
handler with #[tauri_conduit::command] instead:
use tauri_conduit::command;
#[command]
fn divide(a: f64, b: f64) -> Result<f64, String> {
if b == 0.0 { Err("division by zero".into()) }
else { Ok(a / b) }
}
// Preferred:
.handler("divide", divide)Sourcepub fn command_binary<F, A, Ret>(
self,
name: impl Into<String>,
handler: F,
) -> Self
pub fn command_binary<F, A, Ret>( self, name: impl Into<String>, handler: F, ) -> Self
Sourcepub fn channel(self, name: impl Into<String>) -> Self
pub fn channel(self, name: impl Into<String>) -> Self
Register a lossy channel with the default capacity (64 KB).
Oldest frames are silently dropped when the buffer is full. Best for telemetry, game state, and real-time data where freshness matters more than completeness.
§Panics
Panics if the name is empty, contains characters outside [a-zA-Z0-9_-],
or duplicates an already-registered channel name.
Sourcepub fn channel_with_capacity(
self,
name: impl Into<String>,
capacity: usize,
) -> Self
pub fn channel_with_capacity( self, name: impl Into<String>, capacity: usize, ) -> Self
Register a lossy channel with a custom byte capacity.
§Panics
Panics if the name is empty, contains characters outside [a-zA-Z0-9_-],
or duplicates an already-registered channel name.
Sourcepub fn channel_ordered(self, name: impl Into<String>) -> Self
pub fn channel_ordered(self, name: impl Into<String>) -> Self
Register an ordered channel with the default capacity (64 KB).
No frames are ever dropped. When the buffer is full,
PluginState::push returns an error (backpressure). Best for
transaction logs, control messages, and any data that must arrive
intact and in order.
§Panics
Panics if the name is empty, contains characters outside [a-zA-Z0-9_-],
or duplicates an already-registered channel name.
Sourcepub fn channel_ordered_with_capacity(
self,
name: impl Into<String>,
max_bytes: usize,
) -> Self
pub fn channel_ordered_with_capacity( self, name: impl Into<String>, max_bytes: usize, ) -> Self
Register an ordered channel with a custom byte limit.
A max_bytes of 0 means unbounded — the buffer grows without limit.
§Panics
Panics if the name is empty, contains characters outside [a-zA-Z0-9_-],
or duplicates an already-registered channel name.
Sourcepub fn build<R: Runtime>(self) -> TauriPlugin<R>
pub fn build<R: Runtime>(self) -> TauriPlugin<R>
Build the Tauri v2 plugin.
This consumes the builder and returns a TauriPlugin that can be
passed to tauri::Builder::plugin.
§Dispatch model
Commands are dispatched through a two-tier system:
-
#[command]handlers (registered via.handler()) are checked first. These support named parameters,State<T>injection,Resultreturns, and async — full parity with#[tauri::command]. -
Raw Router handlers (registered via
.command(),.command_json(),.command_binary()) are the fallback. These are simplerVec<u8> -> Vec<u8>functions with no injection or async support.
If a command name exists in both tiers, the #[command] handler takes
priority and a debug warning is printed.