#[service]Expand description
Re-export the service macro Marks a trait as an RPC service.
This macro generates:
- Per-method request structs (private)
impl Trait for Client<dyn Trait>so clients can call methods directly<dyn Trait>::serve(impl)method to create a server
§Example
ⓘ
#[rsrpc::service]
pub trait Worker: Send + Sync + 'static {
async fn run_task(&self, task: Task) -> Result<Output, Error>;
async fn status(&self) -> WorkerStatus;
}
// Client: impl Worker for Client<dyn Worker>
// Server: <dyn Worker>::serve(my_impl)§Streaming
Methods returning Result<RpcStream<T>> are automatically handled as
server-side streaming - no special annotation needed:
ⓘ
#[rsrpc::service]
pub trait LogService: Send + Sync + 'static {
async fn stream_logs(&self, filter: Filter) -> Result<RpcStream<LogEntry>>;
}§Local (non-Send) services
Use #[rsrpc::service(?Send)] to allow non-Send futures. This is useful
when your async methods hold non-Send types across await points:
ⓘ
#[rsrpc::service(?Send)]
pub trait LocalWorker: 'static {
async fn run_task(&self, task: Task) -> Result<Output, Error>;
}Note: ?Send services require a single-threaded runtime for the server.