pub trait ConduitHandler:
Send
+ Sync
+ 'static {
// Required method
fn call(
&self,
payload: Vec<u8>,
ctx: Arc<dyn Any + Send + Sync>,
) -> HandlerResponse;
}Expand description
Trait for conduit command handlers, supporting both sync and async.
Generated by #[conduit::command] as a unit struct implementing this
trait. The plugin calls call and branches on
the HandlerResponse variant to handle sync and async uniformly.
§Usage
ⓘ
use conduit::{command, handler};
#[command]
fn greet(name: String) -> String {
format!("Hello, {name}!")
}
#[command]
async fn fetch(id: u64) -> User {
db::get_user(id).await
}
// Both registered the same way:
tauri_plugin_conduit::init()
.handler("greet", handler!(greet))
.handler("fetch", handler!(fetch))
.build()Required Methods§
Sourcefn call(
&self,
payload: Vec<u8>,
ctx: Arc<dyn Any + Send + Sync>,
) -> HandlerResponse
fn call( &self, payload: Vec<u8>, ctx: Arc<dyn Any + Send + Sync>, ) -> HandlerResponse
Execute the handler with the given payload and application context.
The ctx is typically an Arc<AppHandle<Wry>> provided by the
plugin’s protocol handler. Handlers needing State<T> downcast
the context to extract the app handle.