#[rpc]Expand description
Marks an async method as an RPC handler (read-only operations).
Use #[rpc] for methods that do not modify state. These are simple
request/response handlers for queries and reads.
For methods that modify state, use #[workflow] instead.
§Usage
#[entity_impl]
#[state(MyState)]
impl MyEntity {
#[rpc]
async fn get_count(&self) -> Result<i32, ClusterError> {
Ok(self.state().count) // Read-only access
}
#[rpc]
async fn get_status(&self) -> Result<Status, ClusterError> {
Ok(self.state().status.clone())
}
}§Visibility
By default, #[rpc] methods are #[public] (externally callable).
Combine with #[protected] or #[private] to restrict access.
§When to Use
- Use
#[rpc]for read-only queries that don’t modify state - Use
#[workflow]for any operation that callsstate_mut()
§Generated Code
For each #[rpc] method, the macro generates:
- A dispatch arm in
handle_requestfor the method tag - A typed client method with the same signature