Skip to main content

handler

Attribute Macro handler 

Source
#[handler]
Expand description

Marks a method inside a #[restate_sdk::service]/#[object]/#[workflow] impl block as a Restate handler.

use restate_sdk::prelude::*;

struct Greeter;

#[restate_sdk::service]
impl Greeter {
    #[handler]
    async fn greet(&self, _ctx: Context<'_>, name: String) -> HandlerResult<String> {
        Ok(format!("Greetings {name}"))
    }
}

Handlers must be async fn, take &self and a context as their first two arguments, optionally a single input argument, and return Result<T, E> (or HandlerResult<T>). The context type selects the handler kind: Context for services, ObjectContext/SharedObjectContext for virtual objects, WorkflowContext/SharedWorkflowContext for workflows. Override the handler’s Restate name with #[handler(name = "..")]. Marks a method inside a #[restate_sdk::service]/#[object]/#[workflow] impl block as a Restate handler.

This attribute is consumed by the enclosing service macro; on its own it is a no-op.