Skip to main content

object

Attribute Macro object 

Source
#[object]
Expand description

Entry-point macro to define a Restate Virtual object.

For more details, check the service macro documentation.

§Shared handlers

To define a shared handler, use the SharedObjectContext as the handler’s context; exclusive handlers use the ObjectContext. The kind is inferred from the context type.

use restate_sdk::prelude::*;

struct Counter;

#[restate_sdk::object]
impl Counter {
    #[handler]
    async fn add(&self, ctx: ObjectContext<'_>, val: u64) -> Result<u64, TerminalError> {
        Ok(val)
    }
    #[handler]
    async fn get(&self, ctx: SharedObjectContext<'_>) -> Result<u64, TerminalError> {
        Ok(0)
    }
}